0

Friends,

Is there automatic way to generate Makevars and configure? I'm compiling my C++ code using the bash terminal with the g++ compiler.

Example: I have the following code written using the Rcpp.h library where I use a gsl/gsl_sf_bessel.h header file, that is, I use a library external to Rcpp.

#include <Rcpp.h>
#include <gsl/gsl_sf_bessel.h>
using namespace Rcpp;

// [[Rcpp::export]]
double my_bessel(double x){
   return gsl_sf_bessel_J0 (x);
}

In the example above, considering the configurations and path of the headers files of my computer, I can compile the above code using the code below in the bash terminal:

g++ -I"/usr/include/R/" -DNDEBUG -I"/home/pedro/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I"/home/pedro/Dropbox/UFPB/Redes Neurais e Análise de Agrupamento/Rcpp" -D_FORTIFY_SOURCE=2  -fpic  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt  -c program.cpp -o program.o
g++ -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o program.so program.o -L/usr/lib64/R/lib -L/usr/include/gsl -lR -lgsl -gslcblas -lm

Based on the settings and paths of the libraries on my computer, I am able to generate with the above code the object files and the .so file. However, as we know, these paths will not necessarily work when the function is compiled on a different machine than the package user. For this there are Makevars and configure files.

Question: Is there any way to automatically create the Makevars and configure files based on the above build statements?

CXX=g++
CXXFLAGS +=`-O3 -Wall -pipe -Wno-unused -pedantic`
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`  
PKG_LIBS += `gsl-config --libs`

I created the Makevars file with the content just above. However, I'm not sure if there are ways to do this automatically using the build statements presented earlier.

Pedro Rafael
  • 492
  • 4
  • 11
  • Such a tool does not exist, and I would argue, is not needed (or feasible). If you want to contribute one, make a proposal via an issue ticket at the GitHub repository. – Dirk Eddelbuettel May 16 '18 at 16:43
  • 2
    Have you taken a look at [RcppGSL](https://github.com/eddelbuettel/rcppgsl)? seems to take care of most of this for you. – nwknoblauch May 16 '18 at 21:59

0 Answers0