Search code examples
c++stdrcpprcppparallel

std::mt19937 in Rcpp


This problem arose from testing my R (RcppParallel) package on windows through the win-builder-r, as for my mac there is not a problem.

"error: 'mt19937' is not a member of 'std'"

Additionally, this error comes first:

D:/Compiler/gcc-4.9.3/mingw_32/i686-w64-mingw32/include/c++/bits/c++0x_warning.h:32:2: error: #error 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.

A minimal example can be found from this earlier post, use the last : Calling 'mypackage' function within public worker


Solution

  • The <random>header in general and std::mt19337 in particular are only available with C++11 and later. And if you want to use C++11 on Windows in the context of an R package, you are supposed to add

    CXX_STD = CXX11
    

    to src/Makevars.win (Source: Writing R Extensions). On other platforms one often gets by without this, since there newer compilers are used that use C++11 by default. However, please note that WRE discourages the usage of random from C++11, probably because the distribution functions are implementation defined.