我试图用Rcpp代码构建一个使用外部库的R包。我以前曾问过如何在包这里中使用外部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中,以防您需要查看整个包代码,它是可用的这里。
特定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
发布于 2016-06-14 19:48:13
这是一个链接错误,而不是编译错误。编译成功,让您进入链接步骤。但
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非常清楚:r不能构建共享库,因为您没有链接到提供它的对象代码(我想是Sundials )。
https://stackoverflow.com/questions/37819967
复制相似问题