【发布时间】:2016-06-10 16:32:24
【问题描述】:
我正在尝试开发一个 R 包,它使用 Sundials C 库来求解微分方程。为了不让用户安装库,我将库的源代码放在我的包中。
我已将库中的所有头文件放在我的包文件夹的 /inst/include/sundials-2.6.2 和 .c 文件中的 src/sundials-2.6.2 中。
根据我阅读有关此主题的 SO 帖子,sourceCpp 多个文件中的代码(例如,如果将它们构造为包的一部分,则单独的 .h 和 .cpp 文件应该可以工作。我是尝试从 Sundials 包中运行示例代码文件
我的代码(只有开始部分)看起来像
#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 */
但是,我收到一个错误
fatal error: sundials/sundials_nvector.h: No such file or directory
我在以下 github 存储库中做了类似的示例
Rcppsundials - https://github.com/AleMorales/RcppSundials.R/blob/master/src/cvode.cpp
使用
调用头文件#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 机器上安装和运行一个示例,但目前我正在使用没有安装日晷的 Windows 机器工作。它确实安装了Rtools,所以我可以编译并运行示例Rcpp 程序。
谢谢 序列号
【问题讨论】:
-
尝试将
-I src/solver/添加到Makevars中的PKG_CXXFLAGS变量,因为src/solver/sundials/中有sundials/。 -
@nrussell 他链接的 repo 是一个不同的项目,他用作参考来编写自己的项目。
-
啊。错过了那部分。