[Rcpp-devel] cxxfunction -- extra argument to g++

Dirk Eddelbuettel edd at debian.org
Tue Jan 24 21:18:36 CET 2012


On 24 January 2012 at 14:46, Whit Armstrong wrote:
| using cxxfunction is there an easy (not using a custom plugin) way to
| add -std=c++0x to the g++ call?

The best way, I think, is to call a plugin and to modify it.

Quick example:


R> myplugin <- getPlugin("Rcpp")
R> myplugin$env$PKG_CXXFLAGS <- "-std=c++0x"
R> f <- cxxfunction(signature(), settings=myplugin, body='
+    std::vector<double> x = { 1.0, 2.0, 3.0 };  // fails without -std=c++0x
+    return Rcpp::wrap(x);
+ ')
R> f()
[1] 1 2 3
R> 


If you don't use the modified settings, it'll blow up as the 'curly init' is
a new feature:

   filebee52557bd2.cpp:32:44: error: in C++98 ‘x’ must be initialized by constructor, not by ‘{...}’
   filebee52557bd2.cpp:32:44: error: could not convert ‘{1.0e+0, 2.0e+0, 3.0e+0}’ from ‘<brace-enclosed initializer list>’ to ‘std::vector<double>’

but with the switch it all flies.

I think I'll add that to the Rcpp-FAQ now.

Note though that here I simply assigned PKG_CXXFLAGS which had been empty as
the Rcpp plugin does not set it. Other plugins may, so you one may have
append rather than overwrite.

Dirk

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list