Dear all:

 Following my own post about problems with compilation flags in Fedora,
 after having consulted Iñaki Úcar, one of the maintaners of R in Fedora,
 he has said me that the solution of altering the base file of flags
 /usr/lib64/R/etc/Makeconf is not the right way for two reasons:

 - Fedora is quite strict with the policy of flags oriented to crash
 prevention and stringly recommends to use them
 - The file /usr/lib64/R/etc/Makeconf will get overwritten on every
 package update.

 Therefore, the rigth solution he recommends is:

 - Copy the file /usr/lib64/R/etc/Makeconf to any place under
   you $HOME folder with a significant name, let's say 
$HOME/.R/CRANchek.Makevars
   and alter it appropriately with/without the compilation flags you need.
 - Create a .Renviron file (or add this line to the current one):
   R_MAKEVARS_USER=~/.R/CRANcheck.Makevars

 If you want this to apply for all your R executions put .Renviron in your 
$HOME.
 Otherwise, it can be set up per project in the project directory
 (see https://community.rstudio.com/t/location-of-renviron-file/116139)

 Another thing he made me notice is that, even if you compile with
 non-CRAN complaint flags, the real CRAN check is done at the CRAN server,
 where those flags will NOT be used, so the only problem would be the annoying
 WARNING that appears in _your_ machine when you do the R CMD check --as-cran
 But for people doing this firs time, like me, this was still worrying since at
 first you really believe your package will not pass the check...

 Sorry for my mistake in the previous post.

   Juan

El 30/10/22 a las 12:26, Juan Domingo Esteve escribió:
Dear all:

  Yesterday I posted a request for help due to a problem compiling my package
which received inmediate response from Dirk to indicate that obviously the
use of some Rcpp functions could not be the cause of including abort and printf
in the compiled code. Fortunately, I have found the failure and its solution,
which I post to be archived, just in case anyone may use it.

Keywords: compiler options, abort, package check, Fedora

Problem description:

  When compiling a package with C++ source code using Rcpp in a Linux system,
  kernel 5.19.16-100, distribution Fedora 35, the generated package does not
  pass the R CMD check test, giving two warnings and one note.

  The warnings are about the use of abort and printf functios from the
  basic C library, which is not allowed since it would make R crash. Of course,
  the code did not use any of this functions, neither it uses cout or cerr.

  Since the package compiled correctly in another machine, I compared the used
  compilation flags and tried manual compilation getting rid of one of them 
each.
  The offending flag was -Wp,-D_GLIBCXX_ASSERTION and, looking for it, I found
  the note in the R documentation, part 'R Installation and Administration' 
which
  says:

  "Additional compilation flags can be specified for added safety/security 
checks. For example Fedora adds

-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
-Fexceptions -fstack-protector-strong -fasynchronous-unwind-tables
-fstack-clash-protection -fcf-protection

to all the C, C++ and Fortran compiler flags (even though _GLIBCXX_ASSERTIONS 
is only for C++ in current GCC
and glibc and none of these are documented for gfortran). Use of 
_GLIBCXX_ASSERTIONS will link abort and printf
into almost all C++ code, and R CMD check --as-cran will warn."

  Moreover, the inclusion of flag -D_FORTIFY_SOURCE=2 provokes a warning in 
compilation (which
  does not hurt the later check but it is annoying) and also this flag and the 
-Werror=format-security
  rise a note in R CMD check saying:
  Compilation used the following non-portable flag(s):
      ‘-Werror=format-security’ ‘-Wp,-D_FORTIFY_SOURCE=2’
      ‘-Wp,-D_GLIBCXX_ASSERTIONS’

Solution:

  Defaults compilation flags, at least in the Fedora default installation or R, 
are in file

  /usr/lib64/R/etc/Makeconf

  As root or with sudo, make a copy of this file (just in case you make a 
mistake or want to revert changes)
  and edit it getting rid of the -Wp,-D_GLIBCXX_ASSERTION whenever it is used. 
You can also get
  rid of -Werror=format-security and -Wp,-D_FORTIFY_SOURCE=2 if you want to 
avoid the note in check.

I hope this may be useful to anyone else.

  Juan


--
________________________________________________________________
Juan Domingo Esteve
Dept. of Informatics, School of Engineering
University of Valencia
Avda. de la Universidad, s/n.
        46100-Burjasot (Valencia)
           SPAIN

Telephone:      +34-963543572
Fax:            +34-963543550
email:  juan.domi...@uv.es
________________________________________________________________
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to