Using boost multiprecision with Rcpp on Windows

2019-08-24 07:40发布

问题:

I'm trying to compile and use the following code (which I have seen on SO):

// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/multiprecision/float128.hpp>

namespace mp = boost::multiprecision;

// [[Rcpp::export]]
std::string mexp(double mx)
{
  mp::float128 x(mx);
  mp::float128 res = mp::exp(x);
  return res.convert_to<std::string>();
}

Before compiling, I have to do Sys.setenv("PKG_LIBS" = "-lquadmath") otherwise the compilation does not work. Then the compilation runs fine, but when I type mexp(1) in R, the R session totally crashes. Am I missing something ? The session crashes in RStudio as well as in the classical R gui.

PS: I am under Windows and I get the crash with R-3.3.3 as well as R-3.4.1.

Edit:

Just tried on Linux with R-3.4.1 and this works fine. I even don't need to do Sys.setenv("PKG_LIBS" = "-lquadmath").

标签: r boost rcpp