SYSTEM SPEC:
- OS - Mac OS X 10.6.8 (Snow Leopard)
- g++ - Macports gcc 4.8.1_2+universal
- R - 2.15.3
- Rcpp - 0.10.3
I keep on receiving an error when I am trying to compile functions that use C++11 in R (through Rcpp) - for some reason, g++ does not recognise -std=c++11
option.
This example is taken from Rcpp help files (it does not contain anything specific to C++11, but can show what my problem is). If I try running:
require( Rcpp )
Sys.setenv( "PKG_CXXFLAGS"="-std=c++11" )
cppFunction(plugins=c("cpp11"), '
int useCpp11() {
int x = 10;
return x;
}')
I get:
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [file61239328ae6.o] Error 1
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include" -std=c++11 -fPIC -g -O2 -c file61239328ae6.cpp -o file61239328ae6.o
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
Error 1 occurred building shared library.
At the same time, I can compile this function directly from bash - if this code is in useCpp11.cpp
file, then this runs without any complaints:
g++ useCpp11.cpp -std=c++11
Certainly, I am doing something wrong, but I cannot work out what it is. gcc 4.8 is set as a default compiler in bash, Rcpp has been working without fault in the past. I suspect that I am not telling R which version of g++ to use - could that be the case?