在R中使用Rcpp编译.cpp文件时,出现此错误消息:
未定义对`boost :: system :: generic_category()的引用
但是,当我删除// [[Rcpp::plugins(cpp11)]]
行时,就不再有任何错误。为什么?
这是我的最小可重复示例。
// include Rcpp, it takes care of most other headers you need
#include <Rcpp.h>
#include <boost/array.hpp>
// include Boost's odeint
#include <boost/numeric/odeint.hpp>
#include <boost/numeric/odeint/integrate/integrate_adaptive.hpp>
#include <boost/filesystem/fstream.hpp>
#include <functional>
// tell R you need Boost
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]
using namespace Rcpp;
using namespace std;
using namespace boost::numeric::odeint;
typedef boost::array< double ,130 > state_type;
// [[Rcpp::export]]
void my_fun22(Rcpp::NumericVector &x, const double t,const Rcpp::NumericVector theta){
Function f("mod_cpp");
x=f(_["t"]=t,_["x"]=x,_["p1"]=theta);
}
最佳答案
另一个基本问题:Boost系统(通常)需要链接,这与通过BH包仅指向Boost标头完全不同。并且非常标准的错误消息undefined reference
来自链接器/定位符号的失败尝试。
我们在Rcpp Gallery上的某些文章中讨论了链接到Boost库的用法,但是简短的是,没有一种可移植的方法来提供R所使用的跨OS的Boost库的链接。
关于c++ - 添加cpp11插件时出现错误消息“对boost(...)的 undefined reference ”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50469389/