Reputation: 4595
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 -pipe -pedantic -std=gnu99
CXXFLAGS += -O3 -Wall -pipe -Wno-unused -pedantic -fopenmp
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.
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;
}
Call sourceCpp
from R:
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/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
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;
}
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
I only added // [[Rcpp::plugins(cpp11)]]
and it compiles with clang++
instead of clang-omp++
Here is my sessionInfo()
:
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
Upvotes: 14
Views: 7601
Reputation: 4595
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++
See details in this Writing R Extensions section.
Upvotes: 14
Reputation: 368201
I only read one line of your question and stopped there:
I have some strange troubles with Rcpp - it uses unpredictable C++ compiler
That is both wrong and also inflammatory. Please read the R documentation included with your version of R and learn how R sets these things.
Rcpp does nothing extra. All this is default R behaviour:
As a user you can set this in ~/.R/Makevars
As a package author aiming for portable and CRAN-compatible packages you cannot but have to use, say, configure
at package built-time.
This is all documented and has been discussed before.
Upvotes: -3