As described in the post:
Rcpp and boost: it should work but it does not
I am trying to use boost in Rcpp in Windows. The (simplified) file is:
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/multiprecision/float128.hpp>
namespace mp = boost::multiprecision;
// [[Rcpp::export]]
std::string qexp(double da = -1500.0, double db = -1501.0)
{
mp::float128 a(da), b(db);
mp::float128 res = mp::exp(a) / (mp::exp(a) + mp::exp(b));
return res.convert_to<std::string>();
}
I had a compile problem. As @duckmayr suggested in that post, I tried with:
Sys.setenv("PKG_LIBS" = "-lquadmath")
and then Rcpp::sourceCpp('quadexp.cpp')
In this way, the compilation runs without errors. But then, when I execute qexp(), I get a message in RStudio about "fatal error", and RStudio shuts down completely. Do you know what could be happening? I assume my problem is due to some kind of configuration I have, since @duckmayr could run the same code without problems. What parts of my configuration should look at, in order to avoid this nasty "fatal error"?
In addition to the comment above:
edd@rob:~/git/so-r/52933795$ cat code.cpp
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/multiprecision/float128.hpp>
namespace mp = boost::multiprecision;
// [[Rcpp::export]]
std::string qexp(double da = -1500.0, double db = -1501.0) {
mp::float128 a(da), b(db);
mp::float128 res = mp::exp(a) / (mp::exp(a) + mp::exp(b));
return res.convert_to<std::string>();
}
/*** R
qexp()
*/
edd@rob:~/git/so-r/52933795$ Rscript -e 'Rcpp::sourceCpp("code.cpp")'
R> qexp()
[1] "0.731058578630004879251159241821836351"
edd@rob:~/git/so-r/52933795$
Ie using exactly your code (plus an added R invocation) it just works "as is".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.