【发布时间】:2016-01-17 18:15:48
【问题描述】:
我在使用 Rcpp 时遇到了一些奇怪的问题——它使用了不可预测的 C++ 编译器。这个问题有点类似于this question。
我在 OSX 上,我有 2 个编译器 - 默认 clang 和 clang-omp 支持 openmp。我还有以下~/.R/Makevars 文件(我将clang-omp 设置为默认编译器):
CC=clang-omp
CXX=clang-omp++
CFLAGS += -O3 -Wall -pipe -pedantic -std=gnu99
CXXFLAGS += -O3 -Wall -pipe -Wno-unused -pedantic -fopenmp
问题是,我正在开发的包是用clang++ 编译的,而不是clang-omp++。我还尝试(作为解决问题的实验)更改包src/Makevars 并设置CXX=clang-omp++,此外还修改了$R_HOME/etc/MakeconfCXX 条目为CXX = clang-omp++。不走运 - 它仍然与 clang++ 一起编译。不知道为什么会这样。
这里还有一个可重现的小例子(来自控制台 R 和 Rstudio)(不知道它是否与上述问题有关)。
假设 2 个非常相似的 cpp 函数:
1.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
从 R 致电 sourceCpp:
library(Rcpp)
sourceCpp("src/Rcpp_compiler.cpp", verbose = T)
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB -o 'sourceCpp_1.so' 'Rcpp_compiler.cpp'
clang-omp++ -I/Library/Frameworks /R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Users/dmitryselivanov/Library/R/3.2/库/Rcpp/include"-I"/Users/dmitryselivanov/projects/experiments/src"-fPIC -Wall -mtune=core2 -g -O2 -O3 -Wall -pipe -Wno-unused -pedantic -fopenmp -c Rcpp_compiler。 cpp -o Rcpp_compiler.o
clang-omp++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L /usr/local/lib -o sourceCpp_1.so Rcpp_compiler.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
按预期工作 - 使用 clang-omp++ 和我来自 ~/.R/Makevars 的所有标志
2.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB -o 'sourceCpp_2.so' 'Rcpp_compiler.cpp'
clang++ -std=c++11 -I /Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Users/dmitryselivanov/Library/ R/3.2/library/Rcpp/include" -I"/Users/dmitryselivanov/projects/experiments/src" -fPIC -Wall -mtune=core2 -g -O2 -c Rcpp_compiler.cpp -o Rcpp_compiler.o
clang++ -std=c++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/ lib -o sourceCpp_2.so Rcpp_compiler.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
我只添加了// [[Rcpp::plugins(cpp11)]],它编译为clang++而不是clang-omp++
这是我的sessionInfo():
R 版本 3.2.1 (2015-06-18) 平台:x86_64-apple-darwin13.4.0(64位)
运行于:OS X 10.10.5 (Yosemite)
语言环境: 1 en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 附加的基础包:
1 stats graphics grDevices utils datasets methods base
其他附加包: 1Rcpp_0.12.1
通过命名空间加载(未附加): 1tools_3.2.1
【问题讨论】: