Связывание библиотек GSL с RcppGSL в Windows 10 - PullRequest
1 голос
/ 03 мая 2019

Я написал следующий файл .cpp, чтобы извлечь образцы из распределения Дирихле, используя функцию распределения случайных чисел в GSL. Имя файла: C_functions.cpp. Я делаю все в 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);
}

Я создал переменную среды LIB_GSL и установил ее значение как «C: / Users / nkc10 / Documents / R / local323». Это место, куда я разархивировал папку local323.zip, скачанную с по этой ссылке .

Однако, когда я компилирую его с 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.

1 Ответ

1 голос
/ 05 мая 2019

Вы близки, так как вы уже получили файл local323.

Еще два шага:

  1. Скопируйте папку c:\local323\include\gsl в папку RcppGSL (т.е. C:\Users\YOU\Documents\R\win-library\3.6\RcppGSL\include) ИЛИ в каталог вашего проекта. Я попробовал последнее, но я думаю, что это должно работать в любом случае.
  2. Из пакета local323 скопируйте libgsl.a libgslcblas.a в c:\Rtoools\mingw_64\libs. Я понятия не имею, почему он не находит его в вашей папке c: \ local323, но это будет работать.

И я это проверил, твой код работает.

...