Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
219 Views

Error when compiling R from source code (ubuntu 18.04)

Hi all,

I'm trying to compile R 3.4.2 from the source code following this guide:

https://software.intel.com/en-us/articles/build-r-301-with-intel-c-compiler-and-intel-mkl-on-linux

However, I got the following error when building (see below). It builds using gcc without problems.  Do you have an idea of what could be happening?

Best,

Marko

icc -I../../src/extra  -I. -I../../src/include -I../../src/include  -I/usr/local/include -I../../src/nmath -DHAVE_CONFIG_H   -fopenmp -fpic  -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:
           ^

arithmetic.c(63): error: identifier "SING" is undefined
      case SING:
           ^

arithmetic.c(66): error: identifier "OVERFLOW" is undefined
      case OVERFLOW:
           ^

arithmetic.c(69): error: identifier "UNDERFLOW" is undefined
      case UNDERFLOW:
           ^

arithmetic.c(70): error: pointer to incomplete class type is not allowed
  	exc->retval = 0.0;
  	^

compilation aborted for arithmetic.c (code 2)
../../Makeconf:119: recipe for target 'arithmetic.o' failed

 

0 Kudos
4 Replies
Highlighted
Moderator
219 Views

Not sure what happened at your end, but I was able to just follow the steps to build or just recompiled successfully arithmetic.c using your command line above.

$ icc -I../../src/extra  -I. -I../../src/include -I../../src/include  -I/usr/local/include -I../../src/nmath -DHAVE_CONFIG_H   -fopenmp -fpic  -g -O2 -std=c99  -c arithmetic.c -o arithmetic.o
$ ls -lt arithmetic.o
-rw-r--r-- 1 vahoang ome 356200 Jan 22 18:10 arithmetic.o
 

0 Kudos
Highlighted
Moderator
219 Views

These are defined in  /usr/include/math.h

 

331 /* Types of exceptions in the `type' field.  */
332 # define DOMAIN         1
333 # define SING           2
334 # define OVERFLOW       3
335 # define UNDERFLOW      4
336 # define TLOSS          5
337 # define PLOSS          6
 

0 Kudos
Highlighted
219 Views

#EDIT:

WARNING= Doing these give me unexpected results in R test. Finally I decided to try another method.

Thanks for the tip!

I should point that I'm using icc included in Parallel Studio XE 2020 (2020.0.166).

I'm not a C expert but looking at the definitions, I noticed that intel math.h (compilers_and_libraries/linux/include/math.h) defines underscore versions of types of exception (i.e. "_DOMAIN", "_SING", "_OVERFLOW", etc.) as well a four underscore exception structure (typedef struct ____exception). In the other hand, R-3.4.2/src/main/arithmetic.c uses type of except as you describe. I modified the corresponding portion of arithmetic.c to match with intel math.h definitions:

 58 #ifndef __cplusplus
 59 int matherr(struct ____exception *exc)
 60 {
 61     switch (exc->type) {
 62     case _DOMAIN:
 63     case _SING:
 64         errno = EDOM;
 65         break;
 66     case _OVERFLOW:
 67         errno = ERANGE;
 68         break;
 69     case _UNDERFLOW:
 70         exc->retval = 0.0;
 71         break;
 72         /*     
 73            There are cases TLOSS and PLOSS which are ignored here.
 74            According to the Solaris man page, there are for
 75            trigonometric algorithms and not needed for good ones.
 76          */
 77     }   
 78     return 1;
 79 }
 80 #endif

Then it compiled correctly.

Also, my /usr/include/math.h doesn't match with yours so probably it has something to do with the #ifndef __cplusplus in line 58 (as I compiled this modified source code using gcc with default options and it went ok). I haven't tried extensively for errors but it seems to work just fine (I'm on it now).

Viet Hoang (Intel) wrote:

These are defined in  /usr/include/math.h

 

331 /* Types of exceptions in the `type' field.  */
332 # define DOMAIN         1
333 # define SING           2
334 # define OVERFLOW       3
335 # define UNDERFLOW      4
336 # define TLOSS          5
337 # define PLOSS          6
 

0 Kudos
Highlighted
Beginner
219 Views

I encounter the exact same issue with Intel compiler (19.1.1.217) and multiple versions of R (4.0.0 and 3.6.2 so far) under Ubuntu 18.04 (but it is ok with Ubuntu 16.04).

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:

char matherr ();

int main () {
    return matherr();
}


If it compiles fine (with -lm option during linking pass), then HAVE_MATHERR is set 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 was 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 (e.g. using sed).

Regards,

Roland

0 Kudos