首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Rcpp在R包中添加外部库

使用Rcpp在R包中添加外部库
EN

Stack Overflow用户
提问于 2016-06-10 16:32:24
回答 1查看 2.5K关注 0票数 6

我正在尝试开发一个R软件包,它使用日晷 C库来求解微分方程。为了不让用户安装库,我将库的源代码放在包中。

我已经将库中的所有头文件放在/inst/include/sundials-2.6.2中,.c文件放在包文件夹的src/sundials-2.6.2中。

从我阅读有关这个主题的SO文章来看,多个文件中代码的sourceCpp (例如,单独的.h.cpp文件)应该可以工作,如果它们是包的一部分。我正在尝试从Sundials包运行一个示例代码文件。

我的代码(只是开头部分)看起来有点像

代码语言:javascript
复制
#include <Rcpp.h>

#include "../inst/include/sundials-2.6.2/cvode/cvode.h"             /* prototypes for CVODE fcts., consts. */
#include "../inst/include/sundials-2.6.2/nvector/nvector_serial.h"  /* serial N_Vector types, fcts., macros */
#include "../inst/include/sundials-2.6.2/cvode/cvode_dense.h"      /* prototype for CVDense */
#include "../inst/include/sundials-2.6.2/sundials/sundials_dense.h" /* definitions DlsMat DENSE_ELEM */
#include "../inst/include/sundials-2.6.2/sundials/sundials_types.h" /* definition of type realtype */

但是,我收到了一个错误

代码语言:javascript
复制
fatal error: sundials/sundials_nvector.h: No such file or directory

我在下面的github存储库中做了类似的例子

Rcppsundials - https://github.com/AleMorales/RcppSundials.R/blob/master/src/cvode.cpp

调用头文件的

代码语言:javascript
复制
#include <cvodes/cvodes.h>           // CVODES functions and constants
#include <nvector/nvector_serial.h>  // Serial N_Vector
#include <cvodes/cvodes_dense.h>     // CVDense

并将头文件合并到/inst/include/文件夹下。

这是我尝试开发的第一个软件包,而且我也没有广泛地使用C/C++,所以在我试图编译这个程序时可能有一些非常愚蠢的东西。

顺便提醒一下--我能够在我的OSX机器上安装并运行一个示例,但目前我正在一台没有安装Sundials的Windows机器上工作。它确实安装了Rtools,所以我可以编译和运行示例Rcpp程序。

谢谢SN

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-10 17:55:38

外部库链接应通过以下设置完成:

代码语言:javascript
复制
R/
inst/
  |- include/
     |- sundials/ 
  |- header.h
src/
  |- sundials/
  |- Makevars
  |- Makevars.win
  |- action.cpp
man/
DESCRIPTION
NAMESPACE

然后添加以下内容:

代码语言:javascript
复制
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CPPFLAGS =  -I../inst/include/ -I src/sundials

MakevarsMakevars.win

在这里,我选择从文件夹名中删除日晷版本号。

编辑

我已经完成了编译包所需的修补程序:

https://github.com/sn248/Rcppsbmod/pull/1

注意:

其结构是:

代码语言:javascript
复制
inst/
  |- include/
     |- sundials/  
        |- arkode/
        .....
        |- nvector/  
        |- sundials/ 
  |- header.h

这将迫使include语句如下:

代码语言:javascript
复制
#include <sundials/cvodes/cvodes.h>           // CVODES functions and constants
#include <sundials/nvector/nvector_serial.h>  // Serial N_Vector
#include <sundials/cvodes/cvodes_dense.h>     // CVDense

我改变了它是为了:

代码语言:javascript
复制
inst/
  |- include/
     |- arkode/
     .....
     |- nvector/  
     |- sundials/ 
  |- header.h

因此,声明将永远是:

代码语言:javascript
复制
#include <cvodes/cvodes.h>           // CVODES functions and constants
#include <nvector/nvector_serial.h>  // Serial N_Vector
#include <cvodes/cvodes_dense.h>     // CVDense
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37753149

复制
相关文章

相似问题

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