Rcpp 包无法运行 R 3.6 MacOS Mojave。
我运行时出现以下错误
Library(Rcpp)
evalCpp("2 + 2")
输出为:
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
答案1
macOS 10.14 不再将其头文件安装在旧位置。许多第三方安装都会中断,除非您运行:
sudo installer -pkg \
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg \
-target /
也可以看看这个 GitHub 问题。
更新 R 或 macOS(Xcode)时必须重复此命令。
答案2
另一种不需要强制将标题安装在旧位置的解决方案是通过设置以下变量来告诉 R 它们的新位置~/.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
看https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/。