Preparing for CRAN: '-fopenmp' clang error

2019-08-14 18:02发布

问题:

I am preparing a package (which makes use of Rcpp and RcppArmadillo) for submission to CRAN. I am using Travis CI and I have included the following to test my package more thoroughly:

os:
  - linux
  - osx
compiler:
  - clang
  - gcc

This, however, yields the (familiar, it seems) error when using clang on OS X

* installing *source* package ‘my_pkg’ ...
** libs
clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I"/Users/travis/R/Library/Rcpp/include" -I"/Users/travis/R/Library/RcppArmadillo/include" -I/usr/local/include  -fopenmp  -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang: error: unsupported option '-fopenmp'
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘pkg’
* removing ‘/Users/travis/build/my_user/pkg/pkg.Rcheck/pkg’

By appropriately adjusting my travis.yml file to adhere to one of the workarounds suggested here, it seems like I can avoid the issue.

My question is: what should I do if I want to put this on CRAN? Jim's suggestions seems to me only local, do I have to do something in my package to automatically avoid the compile issue for the user in order to be accepted by CRAN?

Edit: To be a little bit more specific, could I just put CXX=g++ in Makevars, or is that frowned upon (and would that be sufficient)?

回答1:

So ... one step at a time, please. Which RcppArmadillo version are you pulling in here? Which clang version are you pulling in? Where is that clang version from? Does it have OpenMP support?

Starting with the previous release of RcppArmadillo, we ensured we simply turn OpenMP off on macOS as the build support is too fragile, see this PR on GitHub. So you may have to remove unconditional use of -fopenmp in your files, or simple not use that "cell" of your Matrix (ie clang && macOS).

Otherwise, the answer by Jim Hester is spot-on. Things are just more work on macOS.