RCPP和Boost:它应该可以工作,但是不可以 [英] Rcpp and boost: it should work but it does not

查看:93
本文介绍了RCPP和Boost:它应该可以工作,但是不可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下有趣的帖子有疑问:

I have a question about the interesting post found at:

具有四精度计算的Rcpp

我使用:

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

如果我理解正确,则无需添加:

If I understand correctly, I do not need to add:

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

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

Since I only want to use float128. When I compile with:

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.

我做错了什么?预先谢谢你.

What am I doing wrong? Thank you in advance.

推荐答案

在Linux 上按原样工作,无需设置环境变量(我现在在-pedantic标志下对充满警告的页面进行模化关闭):

Works "as is" on Linux without setting environment variables (modulo a page full of warnings under the -pedantic flag I now turned off):

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

您可能需要获取Quadmath库.不确定Rtools g ++是否具有它.

You may need to get the quadmath library. Not sure if the Rtools g++ has it.

这篇关于RCPP和Boost:它应该可以工作,但是不可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆