Rcpp 和 boost : it should work but it does not

标签 r boost rcpp

我对在以下位置找到的有趣帖子有疑问:

Rcpp with quad precision computation

我使用:

// [[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>();
// }

如果我没理解错的话,我不需要补充:

Sys.setenv("PKG_LIBS" = "-lmpfr -lgmp")

因为我只想使用 float128。当我编译时:

Rcpp::sourceCpp('/tmp/quadexp.cpp')

我收到一条错误消息:

c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~4/ROPEN~1/R-35~1.1/include" -DNDEBUG   -I"C:/Users/Jordi/Documents/R/win-library/3.5/Rcpp/include" -I"C:/Users/Jordi/Documents/R/win-library/3.5/BH/include" -I"C:/Users/Jordi/Documents"   -I"C:/swarm/workspace/External-R-3.5.1/vendor/extsoft/include"     -O2 -Wall  -mtune=core2 -c quadexp.cpp -o quadexp.o
c:/Rtools/mingw_64/bin/g++ -m64 -shared -s -static-libgcc -o sourceCpp_3.dll tmp.def quadexp.o -LC:/swarm/workspace/External-R-3.5.1/vendor/extsoft/lib/x64 -LC:/swarm/workspace/External-R-3.5.1/vendor/extsoft/lib -LC:/PROGRA~1/MICROS~4/ROPEN~1/R-35~1.1/bin/x64 -lR
quadexp.o:quadexp.cpp:(.text+0x1c9): undefined reference to `expq'
quadexp.o:quadexp.cpp:(.text+0x1df): undefined reference to `expq'
quadexp.o:quadexp.cpp:(.text+0x213): undefined reference to `expq'
quadexp.o:quadexp.cpp:(.text+0x2cc): undefined reference to `quadmath_snprintf'
quadexp.o:quadexp.cpp:(.text+0x30f): undefined reference to `quadmath_snprintf'
collect2.exe: error: ld returned 1 exit status
Error in Rcpp::sourceCpp("C:/Users/Jordi/Documents/quadexp.cpp") : 
  Error occurred building shared library.

我做错了什么?提前谢谢你。

最佳答案

在 Linux 上“按原样”工作无需设置环境变量(在我现在关闭的 -pedantic 标志下取一个充满警告的页面):

R> Rcpp::sourceCpp("/tmp/52876341/q.cpp")
[1] "0.731058578630004879251159241821836351"
R> qexp()
[1] "0.731058578630004879251159241821836351"
R>

您可能需要获取 quadmath 库。不确定 Rtools g++ 是否有它。

关于Rcpp 和 boost : it should work but it does not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52876341/

相关文章:

r - 将数据帧与另一个数据帧的权重相乘

c++ - 如何在线性插值中找到坏点?

c++ - boost asio tcp ip 写入

c++ - boost pool_allocator 内存池行为说明

Rcpp 模块在 Rcpp 0.12.11 中不起作用

r - 在 Rcpp 中调用 R 函数

r - 安装和运行rcpp时出错

r - 如何在 R 中找到具有固定顺序格式的变量的维度?

r -\usepackage{Sweavel} 产生错误 : It seems you are using the Sweave-specific syntax

r - 如何根据矩阵/搜索逻辑生成具有值的新列?