RCPP和默认的C ++编译器 [英] Rcpp and default C++ compiler

查看:152
本文介绍了RCPP和默认的C ++编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Rcpp有一些奇怪的麻烦-它使用了不可预测的C ++编译器.这个问题有点类似于

I have some strange troubles with Rcpp - it uses unpredictable C++ compiler. This question is somewhat similar to this question.
I'm on OSX, I have 2 complilers - default clang and clang-omp with openmp support. Also I have following ~/.R/Makevars file (where I set up clang-omp as default compiler):

CC = clang-omp
CXX = clang-omp ++
CFLAGS + = -O3 -Wall-管道-pedantic -std = gnu99
CXXFLAGS + = -O3 -Wall -pipe -Wno-unnoed -pedantic -fopenmp

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/Makeconf CXX条目设置为CXX = clang-omp++.运气不好-它仍然可以使用clang++进行编译.不知道为什么会发生.

The problem is that, the package I'm developing compiles with clang++, not clang-omp++. I also tried (as experiment to lacate issue) to change package src/Makevars and set CXX=clang-omp++ and moreover modified $R_HOME/etc/Makeconf CXX entry to CXX = clang-omp++. No luck - it still compiles with clang++. Have no idea why it happens.

这也是一个小可重现的示例(从控制台R和Rstudio均可)(不知道它是否与上面的问题有关). 假设2个非常相似的cpp函数:
1.

Also here is small reproducible (both from console R and from Rstudio) example (don't know whether it related to issue above). Suppose 2 very similar cpp functions:
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)

/库/框架/R.framework/资源/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/library/Rcpp/include" -I"/Users/dmitryselivanov/projects/experiments/src" -fPIC -Wall -mtune = core2 -g -O2 -O3 -Wall -pipe -Wno未使用-pedantic -fopenmp -c Rcpp_compiler.cpp -o Rcpp_compiler.o
clang-omp ++ -dynamiclib -Wl,-headerpad_max_install_names-未定义的dynamic_lookup -single_module -multiply_defined抑制-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

/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/library/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

Work as expected - uses clang-omp++ and all my flags from ~/.R/Makevars

2.

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
  return x * 2;
}  

库/框架/R.framework/资源/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"/用户/dmitryselivanov/库/R/3.2/library/Rcpp/include" -I"/用户/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抑制-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

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++

I only added // [[Rcpp::plugins(cpp11)]] and it compiles with clang++ instead of 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 统计图形grDevices utils数据集方法基础
其他附件包: 1 Rcpp_0.12.1
通过名称空间(未附加)加载: 1 tools_3.2.1

R version 3.2.1 (2015-06-18) Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)
locale: 1 en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages: 1 Rcpp_0.12.1
loaded via a namespace (and not attached): 1 tools_3.2.1

推荐答案

感谢@Dirk的提示,我终于得到了答案.希望这可以为某人节省一点时间. ~/.R/Makevars中的以下两行解决了我的问题:

Thanks, to @Dirk hint, I finaly got an answer. Hope, this will save a little bit of time for somebody. Following two lines in ~/.R/Makevars solved my problem:

CXX1X=clang-omp++

查看详细信息,请参见写作R扩展"部分.

这篇关于RCPP和默认的C ++编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆