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
  • 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. Oct 22, 2018 at 16:45

1 Answer 1

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

4
  • OK, I have updated gcc to 8.1.0, and now RStudio does not crashes, and it gives the right output. Strange. Oct 22, 2018 at 17:35
  • R (on Windows) does not use gcc 8.1.0. Did you now switch platforms? But I suspect that some compiler builds you are using do include , and some don't. I vaguely recall that it something new-ish, maybe g++ 4.* ? Oct 22, 2018 at 19:29
  • I saw an answer in stackoverflow of this problem being solved by switching to gcc 6.1. I have googled, and I have found a way to install gcc 8.1 instead of the 4.something in Rtools. Now it works! (no other change). Oct 23, 2018 at 4:46
  • @AnarcocapitalistaSocialdemocr Probably related: sourceforge.net/p/mingw-w64/bugs/368 Oct 23, 2018 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.