0

Rcpp package doesn't run R 3.6 MacOS Mojave.

I've got the following error when I run

Library(Rcpp)

evalCpp("2 + 2")

The output is:

clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include" -I"/private/var/folders/h5/r7lh__p16wx7cg_5pzknfg5w0000gn/T/Rtmpz3QxlQ/sourceCpp-x86_64-apple-darwin15.6.0-1.0.1" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -c file7d712a4a950.cpp -o file7d712a4a950.o
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir,  : 
  Error 1 occurred building shared library.
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
In file included from file7d712a4a950.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:305:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h:301:15: fatal error: 'math.h' file not found
#include_next <math.h>
              ^~~~~~~~
1 error generated.
make: *** [file7d712a4a950.o] Error 1
2
  • What research have you done? What have you tried so far to fix this? – music2myear Jun 3 '19 at 21:49
  • I tried to downgrade R version but I've failed. I did google research about the clang stuff with no results. I´m not a lazy one music2myear – LuisMoncayo Jun 3 '19 at 21:53
1

macOS 10.14 does not install its header files in the old location anymore. Many third-party installations are broken unless you run:

sudo installer -pkg \
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg \
-target /

See also this GitHub issue.

You have to repeat this command when updating R or macOS (Xcode).

1
  • Works for me. I had to install the package directly from Apple developers website. Regards – LuisMoncayo Jun 3 '19 at 14:13
3

Another solution that does not require forced installation of headers in their old location is to tell R their new location by setting the following variables in ~/.R/Makevars:

CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

See https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/.

1
  • 1
    Just to add those three lines didn't work for me. I had to follow the whole procedure outlined in the link above for installing R COMPILER TOOLS FOR RCPP ON MACOS. (thecoatlessprofessor.com/programming/cpp/…). But then it worked like a charm! +1 from me – petzi Oct 26 '19 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.