I have some weird issues with Rcpp - it uses an unpredictable C ++ compiler. This question is somewhat similar to this question .
I'm on OSX, I have 2 complilers - by default clang
and clang-omp
with openmp support. I also have the following ~/.R/Makevars
file (where I installed clang-omp
as the 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 that I am developing compiles with clang++
, rather than clang-omp++
. I also tried (as an experiment to fix the problem) to change the package src/Makevars
and install CXX=clang-omp++
and, in addition, change the $R_HOME/etc/Makeconf
CXX
record to CXX = clang-omp++
. No luck - it still compiles with help clang++
. I donβt know why this is happening.
Also here is a small reproducible example (both from the R console and from Rstudio) (I donβt know if this is due to the problem above). Assume 2 very similar cpp:
1 functions .
#include <Rcpp.h>
using namespace Rcpp;
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 "//dmitryselivanov///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;
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
//R.framework//bin/R CMD SHLIB -o 'sourceCpp_2.so' 'Rcpp_compiler.cpp'
clang++ -std = ++ 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 "//dmitryselivanov/projects/experimental/src" -fPIC -Wall -mtune = core2 - g -O2 -c Rcpp_compiler.cpp -o Rcpp_compiler.o
clang++ -std = ++ 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 ()
: 1 ru_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 :
1 grDevices
: 1 Rcpp_0.12.1
( ): 1 tools_3.2.1