简体   繁体   English

R:互动式RcppGSL使用

[英]R: Interactive RcppGSL use

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. 我正在尝试在64位Windows计算机上使用RcppGSL ,但是觉得我不了解make变量的一些细微差别。

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. 1.从可用二进制安装 GSL 这里在我的最高水平R安装目录中创建一个新的目录。
2. Updated the environment variables to include a new variable LIB_GSL to point to the folder where I unzipped GSL. 2.更新了环境变量,以包括新变量LIB_GSL指向我解压缩GSL的文件夹。
3. Create a set of files in a new directory: 3.在新目录中创建一组文件:
- example1.cpp -example1.cpp
- Makevars.win -Makevars.win

Here is what each of the files looks like. 这是每个文件的外观。

example1.cpp example1.cpp

The example1.cpp file is the basic column norms function that is included as an example in the RcppGSL package itself: example1.cpp文件是RcppGSL程序包本身中包含的示例的基本列规范函数:

// [[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  
}

Makevars.win Makevars.win

PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include 
PKG_LIBS=-L$(LIB_GSL)/lib/x64 -lgsl -lgslcblas

Question: 题:

However, when I sourceCpp the example1.cpp file, it gives me the following output: 但是,当我sourceCpp example1.cpp文件时,它提供了以下输出:

> 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 . 现在,我知道我的文件实际上在-L$(LIB_GSL)/lib/x64 ,但是链接程序在-L$(LIB_GSL)/lib查找(这也反映在我的Makevars.win中),因此是无法找到libgsllibgslcblas How can I enforce that this is the PKG_LIBS passed to cppSource instead of whatever the default is. 我怎么能强制执行,这是PKG_LIBS传递给cppSource ,而不是任何默认为。

My current workaround is to copy everything from -L$(LIB_GSL)/lib/x64 to -L$(LIB_GSL)/lib but not happy with that solution. 我当前的解决方法是将所有内容从-L$(LIB_GSL)/lib/x64复制到-L$(LIB_GSL)/lib但对该解决方案不满意。

The Makevars.win is not used by sourceCpp() . Makevars.win不使用sourceCpp()

When I do this here on Linux, things just work as expected: 当我在Linux上执行此操作时,一切按预期进行:

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. 在Windows上为您使用的是在程序包加载时通过程序包源中的文件R/inline.R确定的,它反映了LIB_GSL内容。

Maybe the line gsl_libs <- sprintf( "-L%s/lib -lgsl -lgslcblas", LIB_GSL ) needs a correction and we need to append /x64 for you? 也许gsl_libs <- sprintf( "-L%s/lib -lgsl -lgslcblas", LIB_GSL )需要更正,我们需要为您附加/x64吗? Could you debug that? 你能调试一下吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM