Reputation: 10954
I am trying to use RcppGSL
on a 64-bit Windows machine, but feel that there are some nuances of the make
variables that I am not understanding.
Here is what I tried:
1. Installed GSL from binaries available here in a new directory I created in the top-level R installation directory.
2. Updated the environment variables to include a new variable LIB_GSL
to point to the folder where I unzipped GSL.
3. Create a set of files in a new directory:
- example1.cpp
- Makevars.win
Here is what each of the files looks like.
The example1.cpp
file is the basic column norms function that is included as an example in the RcppGSL
package itself:
// [[Rcpp::depends(RcppGSL)]]
#include <RcppGSL.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
// [[Rcpp::export]]
Rcpp::NumericVector colNorm(Rcpp::NumericMatrix sM) {
RcppGSL::matrix<double> M(sM); // create gsl data structures from SEXP
int k = M.ncol();
Rcpp::NumericVector n(k); // to store results
for (int j = 0; j < k; j++) {
RcppGSL::vector_view<double> colview = gsl_matrix_column (M, j);
n[j] = gsl_blas_dnrm2(colview);
}
M.free(); // important: GSL wrappers use C structure
return n; // return vector
}
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib/x64 -lgsl -lgslcblas
However, when I sourceCpp
the example1.cpp
file, it gives me the following output:
> Rcpp::sourceCpp('example53[RcppGSL].cpp')
g++ -m64 -I"F:/PROGRA~1/r/R-31~1.1/include" -DNDEBUG -IF:/programming/r/R-3.1.1/GSL/include -I"F:/programming/r/R-3.1.1/library/Rcpp/include" -I"F:/programming/r/R-3.1.1/library/RcppGSL/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c example53[RcppGSL].cpp -o example53[RcppGSL].o
g++ -m64 -shared -s -static-libgcc -o sourceCpp_9705.dll tmp.def example53[RcppGSL].o -LF:/programming/r/R-3.1.1/GSL/lib -lgsl -lgslcblas -LF:/PROGRA~1/r/R-31~1.1/bin/x64 -lRlapack -LF:/PROGRA~1/r/R-31~1.1/bin/x64 -lRblas -lgfortran -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LF:/PROGRA~1/r/R-31~1.1/bin/x64 -lR
f:/programming/r/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lgsl
f:/programming/r/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lgslcblas
collect2: ld returned 1 exit status
Error in Rcpp::sourceCpp("example53[RcppGSL].cpp") :
Error occurred building shared library.
Now, I know that my files are actually in -L$(LIB_GSL)/lib/x64
, but the linker is looking in -L$(LIB_GSL)/lib
(this is reflected in my Makevars.win
as well), hence is not able to find libgsl
or libgslcblas
. How can I enforce that this is the PKG_LIBS
passed to cppSource
instead of whatever the default is.
My current workaround is to copy everything from -L$(LIB_GSL)/lib/x64
to -L$(LIB_GSL)/lib
but not happy with that solution.
Upvotes: 0
Views: 214
Reputation: 368241
The Makevars.win
is not used by sourceCpp()
.
When I do this here on Linux, things just work as expected:
R> sourceCpp("/tmp/coln.cpp") # where coln.cpp is what you have above
R> colNorm(matrix(1:16,4,4))
[1] 5.47723 13.19091 21.11871 29.08608
R>
What is used for you on Windows is determined at package load time via the file R/inline.R
in the package sources, and it reflects what the LIB_GSL
has.
Maybe the line gsl_libs <- sprintf( "-L%s/lib -lgsl -lgslcblas", LIB_GSL )
needs a correction and we need to append /x64
for you? Could you debug that?
Upvotes: 1