【发布时间】:2016-06-14 18:53:33
【问题描述】:
我正在尝试使用Rcpp 代码构建一个使用外部库的 R 包。我之前曾向 SO 询问过如何在包 here 中使用外部 C 库。我遇到的问题是,只要我包含以下代码行
y = N_VNew_Serial(3);
我收到了错误
sundials_test.o:sundials_test.cpp:(.text+0x2ba): undefined reference to `N_VNew_Serial'
collect2: ld returned 1 exit status
Error in Rcpp::sourceCpp("src/sundials_test.cpp") :
Error occurred building shared library
我没有收到该行的错误
N_Vector y = NULL;
所以,我认为与图书馆的连接工作正常。我还确认N_VNewSerial() 的函数声明在nvector/nvector_serial.h 中,如果您需要查看整个包代码,可以使用here
特定Rcpp 文件的代码粘贴在下方
#include <Rcpp.h>
// #include <iostream.h>
#include <cvode/cvode.h> /* prototypes for CVODE fcts., consts. */
#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
#include <cvode/cvode_dense.h> /* prototype for CVDense */
#include <sundials/sundials_dense.h> /* definitions DlsMat DENSE_ELEM */
#include <sundials/sundials_types.h> /* definition of type realtype */
using namespace Rcpp;
void InitialConditions (NumericVector x){
N_Vector y = NULL;
// y = N_VNew_Serial(3);
//
// NV_Ith_S(y,0) = 1;
// NV_Ith_S(y,1) = 2;
// NV_Ith_S(y,2) = 3;
}
我不确定为什么代码将 undefined reference 报告给一个函数,但没有报告给同一个头文件中的另一个函数,非常感谢任何有助于理解解决此错误的方法。
谢谢!
SN248
【问题讨论】:
标签: c++ r rcpp r-package sundials