griffithlab / GenVisR

Genome data visualizations
Creative Commons Zero v1.0 Universal
206 stars 62 forks source link

Installing mgcv dependency erroring on -fopenmp #357

Closed Matthew-Mosior closed 5 years ago

Matthew-Mosior commented 5 years ago

Hi!

I have been trying download the Suggests packages, but am running into issues when trying to install the mgcv R package.

Here is the error message from R:

> install.packages("mgcv")

  There is a binary version available but the source version is later:
     binary source needs_compilation
mgcv 1.8-27 1.8-28              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) yes
installing the source package ‘mgcv’

trying URL 'https://cran.rstudio.com/src/contrib/mgcv_1.8-28.tar.gz'
Content type 'application/x-gzip' length 915991 bytes (894 KB)
==================================================
downloaded 894 KB

* installing *source* package ‘mgcv’ ...
** package ‘mgcv’ successfully unpacked and MD5 sums checked
** libs
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include  -fopenmp -fPIC  -Wall -g -O2  -c coxph.c -o coxph.o
clang: error: unsupported option '-fopenmp'
make: *** [coxph.o] Error 1
ERROR: compilation failed for package ‘mgcv’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/mgcv’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/mgcv’
Warning in install.packages :
  installation of package ‘mgcv’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/n7/kr6qwvgs1bq4p9jfzs6zb77r0000gp/T/RtmpgoWppj/downloaded_packages’

Thanks!!

Matthew Mosior

zlskidmore commented 5 years ago

Hi @Matthew-Mosior

MGCV is not a direct dependency of GenVisR but is probably loaded by one of the packages in the suggests field. It seems like a very low level package.

At any rate this seems like it's a mac issue, more specifically the default c++ compiler distributed by xcode that R is using does not have -fopenmp.

The fix is to install a different compiler and then point R to that, these steps should work:

  1. use homebrew to install gcc brew install gcc@8

  2. find where this gcc is located, for me it's /usr/local/bin/gcc-8 which gcc-8

  3. Tell R to use this compiler by created a Makevars file that R will look at on startup, this should be in ~/.R/Makevars, this is the where R will look on startup

    mkdir ~/.R
    cd ~/.R
    touch Makevars
  4. put these lines in the Makevars file, you might need to change the locations slightly

    CC = /usr/local/bin/gcc-8
    CXX = /usr/local/bin/g++-8
    CFLAGS = -g -O2 -Wall -pedantic -Wconversion -Wno-sign-conversion
    CXXFLAGS = -g -O2 -Wall -pedantic -Wconversion -Wno-sign-conversion
  5. restart R and you should be good to go