[R] Compilation error with Intel compiler & Ubuntu 18.04 related to matherr feature detection
Roland Denis
den|@ @end|ng |rom m@th@un|v-|yon1@|r
Fri May 15 17:00:37 CEST 2020
Hello,
while compiling R (tested with version 4.0.0 and 3.6.2) with Intel
compiler (version 19) under Ubuntu 18.04, I get the following error:
icc -I../../src/extra -I. -I../../src/include -I../../src/include
-I/usr/local/include -I../../src/nmath -DHAVE_CONFIG_H -fopenmp -g -O2
-std=c99 -c arithmetic.c -o arithmetic.o
arithmetic.c(59): warning #274: declaration is not visible outside of
function
int matherr(struct exception *exc)
^
arithmetic.c(61): error: pointer to incomplete class type is not allowed
switch (exc->type) {
^
arithmetic.c(62): error: identifier "DOMAIN" is undefined
case DOMAIN:
^
On the other side, everything works fine with Ubuntu 16.04.
Same error has already been reported on Intel forum
(https://software.intel.com/en-us/forums/intel-c-compiler/topic/843647)
and the remaining of this message is mainly a copy-paste from an answer
that I just post to the Intel forum (waiting for moderation).
From what I understand, it comes from the removal of SVID math library
exception handling (that defines matherr function and exception
structure) from math.h starting with glibc >= 2.27 (see the manpage of
matherr, e.g. here http://man7.org/linux/man-pages/man3/matherr.3.html).
Ubuntu 16.04 is shipped with version 2.23 and Ubuntu 18.04 with version
2.27: the test code from the manpage above compiles fine with gcc 5.5.0
from Ubuntu 16.04 but triggers a compilation error (lack of definition
of exception structure and associated typedefs) with gcc 7.5.0 from
Ubuntu 18.04.
During configuration step of R, it checks for availability of this
exception handling by checking if a matherr function is found during
linking time, i.e. with a likewise minimal code (extracted from the
generated conftext.c):
```
char matherr ();
int main () {
return matherr();
}
```
If it compiles fine (with -lm option during linking pass), then
HAVE_MATHERR is set in src/include/config.h and corresponding code is
visible during compilation of R (the faulty part that triggered an error
in arithmetic.c).
With Ubuntu 16.04, this test code compiles fine with gcc and math.h have
the corresponding definitions (`exception`).
With Ubuntu 18.04, this test code fails at linking step (undefined
reference to matherr), thus hiding associated code in arithmetic.c
Now with Intel compiler, this minimal test code compiles fine both under
Ubuntu 16.04 and 18.04, but math.h from Intel doesn't define the
`exception` structure (only `exceptionf` and `exceptionl`). It is
probably relying on the definitions in the glibc math.h (included in the
beginning of Intel's math.h) that has been removed in glibc >= 2.27.
To resume, R checks for SVID math library exception handling by looking
for the `matherr` symbol in libm and then suppose that the associated
`exception` structure is defined in math.h. While this implication holds
true for GCC (under Ubuntu 16.04 & 18.04), the Intel compiler seems to
always feature the `matherr` symbol while relying on system wide
`math.h` (e.g. glibc) for the associated definitions, definitions that
has been removed in glibc >= 2.27 (Ubuntu 18.04).
The temporary fix that I use is simply to remove HAVE_MATHERR macro in
src/include/config.h from R sources between the configuration and
building steps.
But even if Intel compiler has probably a faulty behavior in this case,
I was wondering if it should be safer to also check for `exception`
structure definition during configuration of R instead of just relying
on matherr symbol existence?
Regards,
--
Roland DENIS
More information about the R-help
mailing list