0

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"?

  • 1. His suggestion for `Sys.setenv()` was _for a different operating system_ on which I don't even need his suggestion. 2. Boost and RStudio have at times conflicted (mostly overthreading), I am not sure if that is the case here. 3. The logical consequence of the previous point is to try the code in R _outside_ of RStudio. 4. As I said in response to your previous (identical?) question, "it just works for me" on Linux with standard CRAN packages. – Dirk Eddelbuettel Oct 22 '18 at 16:45

1 Answers1

1

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$

I.e. using exactly your code (plus an added R invocation) it just works "as is".

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725