[Rcpp-devel] Problem with abort function and compilation in Fedora-Linux

Juan Domingo Esteve Juan.Domingo at uv.es
Sun Oct 30 12:26:14 CET 2022


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.Domingo at uv.es
________________________________________________________________


More information about the Rcpp-devel mailing list