首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用外部C库在Rcpp中编译C++

用外部C库在Rcpp中编译C++
EN

Stack Overflow用户
提问于 2016-06-14 18:53:33
回答 1查看 1.3K关注 0票数 7

我试图用Rcpp代码构建一个使用外部库的R包。我以前曾问过如何在包这里中使用外部C库。我所面临的问题是,只要我包括以下代码行

代码语言:javascript
复制
y = N_VNew_Serial(3);

我收到错误了

代码语言:javascript
复制
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

我没有发现这行的错误

代码语言:javascript
复制
N_Vector y = NULL;

所以,我觉得和图书馆的连接很正常。我还确认了N_VNewSerial()的函数声明在nvector/nvector_serial.h中,以防您需要查看整个包代码,它是可用的这里

特定Rcpp文件的代码粘贴在下面

代码语言:javascript
复制
#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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-14 19:48:13

这是一个链接错误,而不是编译错误。编译成功,让您进入链接步骤。但

代码语言:javascript
复制
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 )。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37819967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档