[Rcpp-devel] Compiling RcppArmadillo through R CMD SHLIB on Windows XP

Romain Francois romain at r-enthusiasts.com
Sun Dec 12 13:15:09 CET 2010


Le 12/12/10 04:03, Savitsky, Terrance a écrit :
> Hello,
>
> I employ a variant of the following lines in a cygwin bash session in
> Windows XP to compile my .cpp file.
>
> $ export PKG_LIBS=`Rscript.exe -e "RcppArmadillo:::LdFlags()"`
>
> $ export PKG_CXXFLAGS=`Rscript.exe -e "RcppArmadillo:::CxxFlags()"`
>
> $ R CMD SHLIB fastLm.cpp
>
> I receive the following compile error:
>
> G++ -I”C:/PROGRA~1/R/R-212~1.0/include” Rscript.exe –e
> ”RcppArmadillo:::CxxxFlags()” –O2 – Wall –pedantic – c fastLm.cpp – o
> fastLm.o
>
> G++:Rscript.exe: No such file or directory
>
> fastLm.cpp:1:27: error: RcppArmadillo.h: No such file or directory
>
> fastLm.cpp:2: error: ‘SEXP’ does not have name a type
>
> I’ve included the R bin directory containing Rscript.exe to the PATH
> environment statement. Should one use a different syntax for windows to
> capture RcppArmadillo dependencies? (Fyi, I am able to build using
> inline, though my code is 600 lines and I will have multiple versions,
> so using the old approach may provide the most modular de-bugging
> approach vs. re-installing a package as I add files).
>
> Thanks, Terrance Savitsky

Another way that is close to what you want to do (but still, please 
follow my previous advice) is to use R's abilities instead of windows:

Consider this simple bla.cpp file :

#include <RcppArmadillo.h>

using namespace Rcpp ;
extern "C" SEXP foo(){
     arma::mat x(2,2) ;
     NumericMatrix res = wrap( x + x ) ;
     return res ;
}


You could R CMD SHLIB it using this little R script (compile.R):

require(RcppArmadillo)

PKG_LIBS <- sprintf( "%s $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", 
Rcpp:::RcppLdFlags() )
PKG_CPPFLAGS <- sprintf( "%s %s", Rcpp:::RcppCxxFlags(), 
RcppArmadillo:::RcppArmadilloCxxFlags() )

Sys.setenv(
     PKG_LIBS = PKG_LIBS ,
     PKG_CPPFLAGS = PKG_CPPFLAGS
)
R <- file.path( R.home(component = "bin"), "R"  )
system( sprintf( "%s CMD SHLIB %s", R, paste( commandArgs(TRUE), 
collapse = " ") ) )


Then you do:

romain at naxos /tmp $ Rscript compile.R bla.cpp
Le chargement a nécessité le package : RcppArmadillo
Le chargement a nécessité le package : Rcpp
Le chargement a nécessité le package : methods
Le chargement a nécessité le package : inline
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include 
-I/Library/Frameworks/R.framework/Resources/include/x86_64 
-I/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/include 
-I"/Library/Frameworks/R.framework/Versions/2.12/Resources/library/RcppArmadillo/include" 
-I/usr/local/include    -fPIC  -g -O3 -Wall -pipe -c bla.cpp -o bla.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined 
dynamic_lookup -single_module -multiply_defined suppress 
-L/usr/local/lib -o bla.so bla.o 
/Library/Frameworks/R.framework/Versions/2.12/Resources/library/Rcpp/lib/x86_64/libRcpp.a 
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack 
-L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas 
-lgfortran -F/Library/Frameworks/R.framework/.. -framework R 
-Wl,-framework -Wl,CoreFoundation


Romain


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/fT2rZM : highlight 0.2-5
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
`- http://bit.ly/hovakS : RcppGSL initial release




More information about the Rcpp-devel mailing list