使用 Xcode 5.0 和 Rcpp 时出错(安装了命令行工具)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19503995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error when with Xcode 5.0 and Rcpp (Command Line Tools ARE installed)
提问by user2904609
I have a new iMac and I'm trying to run code using the Rcpp library that has been working on both my old iMac and Macbook Pro without issue. I have tried everything I can't seem to figure out what the issue is.
我有一台新的 iMac,我正在尝试使用 Rcpp 库运行代码,该库一直在我的旧 iMac 和 Macbook Pro 上运行,没有问题。我已经尝试了所有我似乎无法弄清楚问题所在的方法。
Xcode 5.0 downloaded. Command line Tools then installed. R3.0.2 is installed. I downloaded a gcc compiler. When I type gcc in terminal - I get "clang:" - which is good, I think.
已下载 Xcode 5.0。然后安装命令行工具。安装了 R3.0.2。我下载了一个 gcc 编译器。当我在终端中输入 gcc 时 - 我得到“clang:” - 我认为这很好。
The error I get is copied below. Thanks in advance for any ideas and advice.
我得到的错误复制如下。在此先感谢您的任何想法和建议。
Error (in R console):
llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -fPIC -mtune=core2 -g -O2 -c SBM-Ccode.cpp -o SBM-Ccode.o
Error in sourceCpp("SBM-Ccode.cpp") :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install Command Line Tools for XCode (or equivalent).
/bin/sh: llvm-g++-4.2: command not found
make: *** [SBM-Ccode.o] Error 127
回答by Romain Francois
I'm not sure what you mean by "I downloaded a gcc compiler". You don't need to download your own gcc. You can use either the default or use clang++ by having something like this in your ~/.R/Makevars
file:
我不确定“我下载了 gcc 编译器”是什么意思。您不需要下载自己的 gcc。您可以使用默认值或使用 clang++,方法是在您的~/.R/Makevars
文件中包含以下内容:
CC=clang
CXX=clang++
CXXFLAGS= -O3 -pedantic
What happens when you try devtools::has_devel
:
尝试时会发生什么devtools::has_devel
:
> require(devtools)
> has_devel()
'/Library/Frameworks/R.framework/Resources/bin/R' --vanilla CMD SHLIB foo.c
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -fPIC -mtune=core2 -g -O2 -c foo.c -o foo.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o foo.so foo.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
[1] TRUE
or Rcpp::evalCpp
:
或Rcpp::evalCpp
:
> require(Rcpp)
> evalCpp( "1+1")
[1] 2
回答by Dirk Eddelbuettel
Quick guess:
快速猜测:
You are running the pre-built R binary which Simon built / CRAN provides.
R stores its configuration options from its compile time, those influence its run-time.
Check via the file
$R_HOME/etc/Makeconf
and look at CC and CXX.As Romain suggested, override
CC
andCXX
via a file~/.R/Makevars
.Try again.
您正在运行 Simon 构建 / CRAN 提供的预构建 R 二进制文件。
R 存储其编译时的配置选项,这些选项会影响其运行时。
通过文件检查
$R_HOME/etc/Makeconf
并查看 CC 和 CXX。正如 Romain 建议的那样,覆盖
CC
并CXX
通过文件~/.R/Makevars
.再试一次。
Edit:I just confirmed with a colleague who has the exact same issue on a Mac OS X which
he just upgrades to XCode 5 -- one now needs to override CC
and CXX
as R was built with the previous version of XCode.
编辑:我刚刚与一位同事确认,他在 Mac OS X 上遇到了完全相同的问题,他刚刚升级到 XCode 5——现在需要覆盖CC
,CXX
因为 R 是用以前版本的 XCode 构建的。
回答by Housen
A easier solution would be the following. You should soft link the llvm compiler, in the terminal type:
一个更简单的解决方案如下。您应该在终端类型中软链接 llvm 编译器:
cd /usr/bin
sudo ln -fs clang llvm-gcc-4.2
sudo ln -fs clang++ llvm-g++-4.2
Note: This also works for mex in Matlab.
注意:这也适用于 Matlab 中的 mex。