Linking to another package with R inline
I have a C++/Rcpp function the I need to compile and link to the pomp package to get access to a random number generator. I can get the header file included but how to I get it to link to the compiled code?
CppColonized<-cxxfunction(
sig=signature(x="numeric", t="numeric", params="numeric", dt="numeric"),
plugin='Rcpp',
includes = sprintf("#include <Rmath.h>\n#include <math.h>\n#include\"%s\"",
base:::system.file("include/pomp.h",package="pomp")),
body=Code,verbose=T)
The code uses the reulermultinom function in the pomp package and when I evaluate it it gives the error
undefined reference to `reulermultinom(int, double, double*, double, double*)
The commands being issued are
g++ -I"C:/PROGRA~1/R/R-211~1.1/include" -I"C:/PROGRA~1/R/R-211~1.1/library/Rcpp/include" -O2 -Wall -c file开发者_如何转开发2f752742.cpp -o file2f752742.o g++ -shared -s -static-libgcc -o file2f752742.dll tmp.def file2f752742.o C:/PROGRA~1/R/R-211~1.1/library/Rcpp/lib/libRcpp.a -LC:/PROGRA~1/R/R-211~1.1/bin -lR
Is seems like there should be a -lpomp or something like that.
Please see the documentation for cxxfunction()
and getPlugin()
in package inline.
You need to fill in proper -I... and -L... flags. The sprintf()
hack helps for the header, it doesn't give you the library location.
Also, yesterday's hint about using rcpp-devel still holds. You got three high-quality replies there today. so why not use it. I think we have examples for this in the mailing list archives too.
精彩评论