0

I am trying to build an R package which includes Rcpp and RcppArmadillo code. sourceCpp() works fine and everything runs smoothly, but when I try to build the package I get: "This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options."

Including RcppArmadillo and Rcpp11 in the description file does not seem to help (see below)

My description file includes:

Imports:
  Rcpp (>= 0.12.13),
  RcppArmadillo (>= 0.7.900.2.0),
  Rcpp11 (>=    3.1.1.0),
  data.table
LinkingTo: Rcpp, RcppArmadillo, Rcpp11

I've not included the two .cpp files as they are fairly long, but obviously the issue seems to be the use of C++11 syntax.

Seth
  • 19
  • 4
  • What package? What does the documentation say? What compiler are you using? What platform? No detail given here. – Lightness Races in Orbit Jun 25 '19 at 21:25
  • 3
    You approximately never want both the (actively maintained) `Rcpp` package and the somewhat "dormant" (in the Monty Python parrot skit sense) `Rcpp11`. And you turn C++11 on via either `src/Makevars*` or `SystemRequirements`, see Writing R Extensions or _many_ existing CRAN packages for more. – Dirk Eddelbuettel Jun 25 '19 at 21:36

2 Answers2

4

Rcpp11 is not Rcpp. Said in another way, Rcpp11 and Rcpp are two separate R packages that provide the "glue" between R and C++ objects. As a result, they have fundamentally different APIs.

Removing Rcpp11 from the DESCRIPTION file should allow everything to work.

Imports:
  Rcpp (>= 0.12.13),
  RcppArmadillo (>= 0.7.900.2.0),
  data.table
LinkingTo: Rcpp, RcppArmadillo

To enable C++ 11 use in both src/Makevars and src/Makevars.win:

CXX_STD = CXX11 # Required for C++11
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

Note: The latter two lines are required for RcppArmadillo. For an example package that uses C++-11 please see: https://github.com/r-pkg-examples/rcpp-cpp11-usage

coatless
  • 20,011
  • 13
  • 69
  • 84
  • I'm having trouble understanding the purpose of the `Rcpp11` package. Could you describe a use case? – thc Jun 25 '19 at 22:12
  • 3
    There really isn't a use case for `Rcpp11` due to its dormant development status. With this being said, `Rcpp11` was designed to improve how the transference between _R_ and _C++_ objects occurred by exploiting C++11 and greater language features. Though, this would result in deprecated support for C++98 features. However, that has yet to occur due to a majority of the platforms still shipping old compilers. – coatless Jun 25 '19 at 22:19
1

Found the solution on Dirk's post. In the Makevars and Makevars.win files the option

CXX_STD = CXX11

was out-commented. Include this option (delete the '#') and it builds no problem.

Seth
  • 19
  • 4