Using 3rd party header files with Rcpp

后端 未结 7 1943
生来不讨喜
生来不讨喜 2020-12-12 15:18

I have a header file called coolStuff.h that contains a function awesomeSauce(arg1) that I would like to use in my cpp source file.

Directo

7条回答
  •  自闭症患者
    2020-12-12 15:57

    I was able to link any library (MPFR in this case) by setting two environment variables before calling sourceCpp:

    Sys.setenv("PKG_CXXFLAGS"="-I/usr/include")
    Sys.setenv("PKG_LIBS"="-L/usr/lib/x86_64-linux-gnu/ -lm -lmpc -lgmp -lmpfr")
    

    The first variable contains the path of the library headers. The second one includes the path of the library binary and its file name. In this case other dependent libraries are also required. For more details check g++ compilation and link flags. This information can usually be obtained using pkg-config:

    pkg-config --cflags --libs mylib
    

    For a better understanding, I recommend using sourceCpp with verbose output in order to print the g++ compilation and linking commands:

    sourceCpp("mysource.cpp", verbose=TRUE, rebuild=TRUE)
    

提交回复
热议问题