[英]Linking GSL libraries to RcppGSL in Windows 10
I have written the following .cpp file to draw samples from Dirichlet distribution using the random number distribution function in GSL.我编写了以下 .cpp 文件,使用 GSL 中的随机数分布函数从狄利克雷分布中抽取样本。 The filename is C_functions.cpp.
文件名为 C_functions.cpp。 I am doing everything in Windows 10.
我在 Windows 10 中做所有事情。
#include <RcppArmadillo.h>
#include <RcppGSL.h>
// #include <Rcpp.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(RcppGSL)]]
using namespace arma;
// [[Rcpp::export]]
vec rdirichlet_arma(vec a){
const gsl_rng_type * T;
gsl_rng * r;
/* create a generator chosen by the
environment variable GSL_RNG_TYPE */
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
/* print n random variates chosen from
the poisson distribution with mean
parameter mu */
int n=a.size();
vec results(n);
gsl_ran_dirichlet(r, n, a.begin(), results.begin());
gsl_rng_free (r);
a.reset();
return results;
}
// [[Rcpp::export]]
double pow2(double x){
return gsl_pow_2(x);
}
I have created an environmental variable LIB_GSL and set its value as "C:/Users/nkc10/Documents/R/local323".我创建了一个环境变量 LIB_GSL 并将其值设置为“C:/Users/nkc10/Documents/R/local323”。 This is the location where I unzipped the local323.zip folder downloaded from this link .
这是我解压缩从此链接下载的 local323.zip 文件夹的位置。
However, when I compile it with sourceCpp the following error is shown但是,当我用 sourceCpp 编译它时,会显示以下错误
>C:/RBuildTools/3.5/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-35~1.2/include" -DNDEBUG -I../inst/include -fopenmp -I/include -I"C:/Users/nkc10/Documents/R/win-library/3.5/Rcpp/include" -I"C:/Users/nkc10/Documents/R/win-library/3.5/RcppArmadillo/include" -I"C:/Users/nkc10/Documents/R/win-library/3.5/RcppGSL/include" -I"C:/Users/nkc10/Dropbox/Research/sparse_bayesian_infinite_factor_models-master" -O2 -Wall -mtune=generic -c C_functions.cpp -o C_functions.o
In file included from C:/Users/nkc10/Documents/R/win-library/3.5/RcppGSL/include/RcppGSL.h:25:0,
from C_functions.cpp:2:
C:/Users/nkc10/Documents/R/win-library/3.5/RcppGSL/include/RcppGSLForward.h:26:29: fatal error: gsl/gsl_vector.h: No such file or directory
#include <gsl/gsl_vector.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-35~1.2/etc/x64/Makeconf:215: C_functions.o] Error 1
Error in sourceCpp("C_functions.cpp") :
Error 1 occurred building shared library.
You are close, since you already got the local323 file.您已经接近了,因为您已经获得了 local323 文件。
Two more steps:还有两个步骤:
c:\\local323\\include\\gsl
folder into your RcppGSL folder (ie, C:\\Users\\YOU\\Documents\\R\\win-library\\3.6\\RcppGSL\\include
) OR into your project directory.c:\\local323\\include\\gsl
文件夹复制到您的 RcppGSL 文件夹(即C:\\Users\\YOU\\Documents\\R\\win-library\\3.6\\RcppGSL\\include
)或到您的项目目录中。 I tried the latter, but I think it should work either way.libgsl.a
libgslcblas.a
to c:\\Rtoools\\mingw_64\\libs
.libgsl.a
libgslcblas.a
复制到c:\\Rtoools\\mingw_64\\libs
。 I have no idea why it doesn't find it in your c:\\local323 folder, but this will work. And I tested it, your code works.我测试了它,你的代码有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.