简体   繁体   English

我收到Boost和Rcpp的致命错误

[英]I receive a fatal error with boost and Rcpp

As described in the post: 如文章所述:

Rcpp and boost: it should work but it does not RCPP和Boost:它应该工作,但不起作用

I am trying to use boost in Rcpp in Windows. 我试图在Windows中的Rcpp中使用boost。 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: 正如@duckmayr在该帖子中建议的那样,我尝试使用:

Sys.setenv("PKG_LIBS" = "-lquadmath")

and then Rcpp::sourceCpp('quadexp.cpp') 然后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. 但是,当我执行qexp()时,在RStudio中收到一条有关“致命错误”的消息,RStudio完全关闭。 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. 我认为我的问题是由于我具有某种配置,因为@duckmayr可以毫无问题地运行相同的代码。 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". 完全使用您的代码(加上添加的R调用),它只能“按原样”工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM