0

I'm running RServer Studio on a Linux box on AWS.

I tried to install ModelMetrics, a dependency for caret, and received this error:

auc_.cpp:2:10: fatal error: omp.h: No such file or directory
 #include <omp.h>
          ^~~~~~~
compilation terminated.
make: *** [auc_.o] Error 1
ERROR: compilation failed for package ‘ModelMetrics’

This is the full output message

Installing package into ‘/home/User/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/ModelMetrics_1.2.2.tar.gz'
Content type 'application/x-gzip' length 16974 bytes (16 KB)
==================================================
downloaded 16 KB

* installing *source* package ‘ModelMetrics’ ...
** package ‘ModelMetrics’ successfully unpacked and MD5 sums checked
** libs
g++  -I"/opt/R/3.5.3/lib64/R/include" -DNDEBUG  -I"/home/User/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include   -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++  -I"/opt/R/3.5.3/lib64/R/include" -DNDEBUG  -I"/home/User/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include   -fpic  -g -O2  -c auc_.cpp -o auc_.o
auc_.cpp:2:10: fatal error: omp.h: No such file or directory
 #include <omp.h>
          ^~~~~~~
compilation terminated.
make: *** [auc_.o] Error 1
ERROR: compilation failed for package ‘ModelMetrics’
* removing ‘/home/User/R/x86_64-pc-linux-gnu-library/3.5/ModelMetrics’
Warning in install.packages :
  installation of package ‘ModelMetrics’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/Rtmpr06k8i/downloaded_packages’

I looked around SO and it looks like there is an error with the compiler. I tried the solutions listed here, specifically I ran these commands

yum groupinstall 'Development Tools'
mkdir ~/.R
echo "CC=gcc64" >> ~/.R/Makevars
sudo sed -i 's/CC = gcc -m64/CC = gcc64 -m64/g' /usr/lib64/R/etc/Makeconf

Even after restarting RStudio Server, I get the same output and error message.

It looks like this error is very similar to the problem here. I still don't have a solution after following those instructions, but I did find the location of my omp.h file.

/usr/lib/gcc/x86_64-amazon-linux/4.4.6/include/omp.h
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/include/omp.h
/usr/lib/gcc/x86_64-amazon-linux/6.4.1/include/omp.h

I installed Developer Tools and updated the Makeconf file using these commands.

sudo sed -i 's/CC = gcc -m64/CC = gcc64 -m64/g' /usr/lib64/R/etc/Makeconf
sudo yum groupinstall 'Development Tools'

Then, I added these lines to the Makevars config file.

mkdir ~/.R
vi ~/.R/Makevars

CC=gcc
VER=64
CC=gcc$(VER)
CXX=g++$(VER)
CXX11=g++$(VER)
CXX14=g++$(VER)

I restarted the RStudio Server and tried to install ModelMetrics and received this error, the same as before.

Installing package into ‘/home/User/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/ModelMetrics_1.2.2.tar.gz'
Content type 'application/x-gzip' length 16974 bytes (16 KB)
==================================================
downloaded 16 KB

* installing *source* package ‘ModelMetrics’ ...
** package ‘ModelMetrics’ successfully unpacked and MD5 sums checked
** libs
g++  -I"/opt/R/3.5.3/lib64/R/include" -DNDEBUG  -I"/home/User/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include   -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++  -I"/opt/R/3.5.3/lib64/R/include" -DNDEBUG  -I"/home/User/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I/usr/local/include   -fpic  -g -O2  -c auc_.cpp -o auc_.o
auc_.cpp:2:10: fatal error: omp.h: No such file or directory
 #include <omp.h>
          ^~~~~~~
compilation terminated.
make: *** [auc_.o] Error 1
ERROR: compilation failed for package ‘ModelMetrics’
* removing ‘/home/User/R/x86_64-pc-linux-gnu-library/3.5/ModelMetrics’
Warning in install.packages :
  installation of package ‘ModelMetrics’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpTSUlz4/downloaded_packages’
Cauder
  • 2,157
  • 4
  • 30
  • 69

2 Answers2

1

You have configured R to use gcc64 when compiling C files, but C++ files will still be compiled with g++ instead of g++64. The following configuration in ~/.R/Makevars will change that consistently:

VER=64
CC=gcc$(VER)
CXX=g++$(VER)
CXX11=g++$(VER)
CXX14=g++$(VER)

Since the above does not work for you, you might be affected by the same issues as this user: https://stackoverflow.com/a/49876044/8416610 In that case you can edit R's Makeconf file with

sudo sed -i 's/g++/g++64/' $(R RHOME)/etc/Makeconf

(assuming you alredy changed gcc to gcc64)

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • I'm not sure how to make a config file. Do I just copy and paste those commands? – Cauder Apr 11 '19 at 15:48
  • I added that, and I also installed Development Tools and ran `sudo sed -i 's/CC = gcc -m64/CC = gcc64 -m64/g' /usr/lib64/R/etc/Makeconf`, but I get the same error – Cauder Apr 11 '19 at 16:16
  • @Cauder Please post the full error output after this change. – Ralf Stubner Apr 11 '19 at 16:18
  • I'll do that. Thanks Ralf. – Cauder Apr 11 '19 at 16:30
  • Is it possible that I should delete gcc 7.1 since my older version has an omp file? – Cauder Apr 11 '19 at 17:15
  • @Cauder Some peopel had successs with that: https://forums.aws.amazon.com/thread.jspa?threadID=272761. But nore the caveat in the last message. – Ralf Stubner Apr 11 '19 at 17:31
  • 1
    Got it! These two lines fixed it `sudo yum remove gcc72-c++.x86_64 libgcc72.x86_64 sudo yum groupinstall 'Development Tools'` – Cauder Apr 11 '19 at 17:31
  • I see your link had the same information. If you add it to your post, I'll mark it as the correct answer. Thanks for your help, I'm glad we got through this! – Cauder Apr 11 '19 at 17:33
  • @Cauder it makes more sense if you accept your own answer. I am not using Amazon Linux, so it I cannot give advise on which packages to install/remove. BTW, the final comment in https://stackoverflow.com/a/54111148/8416610 is also interesting. For some reason gcc 7.2 in Amazon Linux is compiled without OpenMP support. – Ralf Stubner Apr 11 '19 at 17:40
0

It turns out that there was something wrong with the version of gcc on the linux box.

Per the instructions here, I was able to fix the problem with these two lines of code.

sudo yum remove gcc72-c++.x86_64 libgcc72.x86_64
sudo yum groupinstall 'Development Tools'
Cauder
  • 2,157
  • 4
  • 30
  • 69