[Rcpp-devel] Compile RcppEigen code using SHLIB

Dirk Eddelbuettel edd at debian.org
Thu Jun 28 13:27:04 CEST 2012

On 27 June 2012 at 22:08, Søren Højsgaard wrote:
| I would like to compile .cpp code based on RcppEigen using R CMD SHLIB. 
| To test this I have created a "sample" package using: RcppEigen.package.skeleton( "foobar" )
| In the src directory of foobar there is a sample .cpp file which I try to compile with (I am on Windows 7)
| C:\Documents\stat\Rdevel\gRbaseDEVEL\foobar\src>R CMD SHLIB rcppeigen_hello_world.cpp
| g++ -m64 -I"C:/programs/R/current/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall
|  -mtune=core2 -c rcppeigen_hello_world.cpp -o rcppeigen_hello_world.o
| In file included from rcppeigen_hello_world.cpp:1:0:
| rcppeigen_hello_world.h:4:23: fatal error: RcppEigen.h: No such file or directory
| compilation terminated.
| make: *** [rcppeigen_hello_world.o] Error 1
| The automatically created Makevars.win file contains the line:
| PKG_LIBS = $(shell $(R_HOME)/bin/Rscript.exe -e "Rcpp:::LdFlags()")
| - and this does not seem to catch RcppEigen.h which is in /library/RcppEigen. 
| Question: Can anyone tell what should be written in the Makevars to be able to compile using R CMD SHLIB ??
| Thanks in advance.

This is addressed in principle in the Rcpp-FAQ (though not for the RcppEigen
case specifically): just get something working eg via inline and look _very
closely_ at what you see when cxxfunction() runs _and have verbose=TRUE set_.
Then copy all the required -I and -L flags by hand to PKG_LIBX, PKG_CPPFLAGS,
PKG_CXXFLAGS as needed.  Et voila -- it'll work.

You "just" have to do a lot more legwork yourself if you do it that way. But
as inline / cxxfunction do in fact call R CMD SHLIB for you ... there is a
working stanza to go from.

| Best regards
| Søren
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  

More information about the Rcpp-devel mailing list