[R-pkg-devel] R package build- C compilation issue related to math.h

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Thu Oct 20 10:35:38 CEST 2022


On Wed, 19 Oct 2022 23:39:57 +0100
Vincent Plagnol <vincent.plagnol using gmail.com> wrote:

> gcc-12 -I"/home/hornik/tmp/R/include" -DNDEBUG   -I/usr/local/include
> -DUSE_TYPE_CHECKING_STRICT -D_FORTIFY_SOURCE=2   -fpic  -g -O2 -Wall
> -Wstrict-prototypes -pedantic -mtune=native  -c VP_gamma.c -o
> VP_gamma.o

> /usr/include/x86_64-linux-gnu/bits/mathcalls.h:85:1: error:
> expected ‘;’ before ‘extern’ 

> It is painful to debug because I don't have a debian machine.
> Furthermore the issue seems to be in the file called at line 22 of
> gsl_math.h which is #include <math.h>

For what it's worth, I couldn't reproduce the problem when compiling
VP_gamma.c from https://github.com/vplagnol/ExomeDepth on two of my
Debian machines with older GCC versions; you might actually need GCC 12
to see it.

I see that VP_gamma.c includes config.h before including gsl_math.h.
Typically, config.h should be automatically generated by the configure
script and may contain different definitions on different systems.
Somebody else has a similar problem, also in math.h, also with a file
that includes config.h before math.h:
https://github.com/vplagnol/ExomeDepth/issues/50

I think that config.h defines something in its /* Substitute gsl
functions for missing system functions */ section that confuses the
glibc math.h machinery. If you have to include config.h in a source
file, it might help to process the system headers first.

I had a related problem recently: MinGW was complaining about a
strftime call in bundled code that wasn't reachable from R anyway, so I
decided to patch it out using the preprocessor. The correct way to do
so is to #include the system header first, then re-#define the function
to nothing:
https://github.com/aitap/Ropj/commit/a7d6cec19d11d47d731fbadbf8735660e534efaa

Otherwise the re-definition affects the system header where the
function is declared and the result is syntactically invalid.

> 	[[alternative HTML version deleted]]

Sorry, the mailing list ate the HTML version of your e-mail, and the
plain text version automatically prepared by your mailer is not easy to
read: https://stat.ethz.ch/pipermail/r-package-devel/2022q4/008578.html

Please post in plain text.

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list