Adding an external library in R package using Rcpp

后端 未结 1 767
轮回少年
轮回少年 2021-01-01 05:11

I am trying to develop an R package which uses the Sundials C library for solving differential equations. In order to not have the user install the library, I am putting the

相关标签:
1条回答
  • 2021-01-01 06:17

    External library linking should be done with the following setup:

    R/
    inst/
      |- include/
         |- sundials/ 
      |- header.h
    src/
      |- sundials/
      |- Makevars
      |- Makevars.win
      |- action.cpp
    man/
    DESCRIPTION
    NAMESPACE
    

    Then add the following:

    PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
    PKG_CPPFLAGS =  -I../inst/include/ -I src/sundials
    

    To both Makevars and Makevars.win

    Here I've opted to remove the sundial version numbers from the folder names.

    Edit

    I've made the fixes necessary to compile the package:

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

    Note:

    The structure was:

    inst/
      |- include/
         |- sundials/  
            |- arkode/
            .....
            |- nvector/  
            |- sundials/ 
      |- header.h
    

    This would have forced the include statements to be:

    #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
    

    I changed it so that:

    inst/
      |- include/
         |- arkode/
         .....
         |- nvector/  
         |- sundials/ 
      |- header.h
    

    So, the statements will always be:

    #include <cvodes/cvodes.h>           // CVODES functions and constants
    #include <nvector/nvector_serial.h>  // Serial N_Vector
    #include <cvodes/cvodes_dense.h>     // CVDense
    
    0 讨论(0)
提交回复
热议问题