0

I want to use boost/multiprecision with Rcpp. Therefore I looked around and found these threads about boost: one and two. The first one about quad-precision is exactly what I want to use. The problem is that I cannot compile the given example. However, I can compile the example from the second thread which just uses a different directory in the boost package. So I'm at a loss as to what is going wrong. Relevant code from the first thread:

// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/multiprecision/float128.hpp>
#include <boost/multiprecision/mpfr.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>();
}

// [[Rcpp::export]]
std::string mpfr_exp(double da = -1500.0, double db = -1501.0)
{
    mp::mpf_float_100 a(da), b(db);
    mp::mpf_float_100 res = mp::exp(a) / (mp::exp(a) + mp::exp(b));
    return res.convert_to<std::string>();
}

The error I get is: ".../R/win-library/3.3/BH/include/boost/multiprecision/gmp.hpp:21:17: fatal error: gmp.h: No such file or directory #include ". But when I browse to: ".../R/win-library/3.3/BH/include/boost/multiprecision/" the file "gmp.hpp" is there. I already tried running "Sys.setenv("PKG_LIBS" = "-lmpfr -lgmp")" as described in the first thread, but no luck. Any suggestions? In case it matters, I'm using windows.

Community
  • 1
  • 1
Vandenman
  • 3,046
  • 20
  • 33
  • What version of BH are you using? – nrussell Feb 27 '17 at 12:04
  • I'm using BH_1.62.0-1. – Vandenman Feb 27 '17 at 12:07
  • 1
    You will need to install the [GMP library](http://cs.nyu.edu/~exact/core/gmp/index.html) (most likely the MinGW variant). The issue cited is not with the file `boost/multiprecision/gmp.hpp`, but the fact that this header contains `#include `. `boost/multiprecision/gmp.hpp` is just a sort of wrapper around the core GMP library, so you will still need `` on your system to use the Boost classes that provide GMP functionality. – nrussell Feb 27 '17 at 12:15
  • Okay, luckily I already did that. Then how do I tell R where it is? (I installed it in "C:\c++\gmp\gmp-6.1.2"). The "gmp.h" file is present in the main folder. – Vandenman Feb 27 '17 at 12:18
  • 1
    Try running `Sys.setenv("PKG_CPPFLAGS" = "-IC:\c++\gmp\gmp-6.1.2")` (or whichever directory `gmp.h` is located in) before compiling. – nrussell Feb 27 '17 at 12:34
  • 3
    @nrussell is too modest as he _just_ created a tutorial for this [over at this SO answer](http://stackoverflow.com/a/42307240/143305). – Dirk Eddelbuettel Feb 27 '17 at 12:38
  • So I tried `Sys.setenv("PKG_CPPFLAGS" = "-IC:/c++/gmp/gmp-6.1.2")` but now I get the error `#include ` not found. I guess I'll have to install GNU MPFR first and then add that to PKG_CPPFLAGS in the same way? – Vandenman Feb 27 '17 at 12:58

0 Answers0