I'm trying to develop an R package, which makes use of Arrayfire, thanks to Rcpp library. I've started writing a sample code (let's name it hello_world.cpp) which looks like this:
#include <arrayfire.h>
// [[Rcpp::export]]
bool test_array_fire(){
af::randu(1, 4);
return true;
}
Then, I tried to compile it using a sourceCpp
function
Rcpp::sourceCpp('src/hello_world.cpp')
My first suprise was the fact I had to set some flags manually (sourceCpp
seems to ignore Makevars config when compiling a piece of C++ code).
I did it with:
Sys.setenv("PKG_CXXFLAGS"="-std=c++11")
Sys.setenv("PKG_CPPFLAGS"="-I/opt/arrayfire/include/")
Sys.setenv("PKG_LIBS"="-L/opt/arrayfire/lib64/ -laf")
However, the code still does not compile properly. Each trial finishes with the following output:
Error in 'dyn.load("/tmp/RtmpHaODIU/sourceCpp-x86_64-pc-linux-gnu-1.0.2/sourcecpp_689c5adb8d/sourceCpp_14.so")':
unable to load shared object '/tmp/RtmpHaODIU/sourceCpp-x86_64-pc-linux-gnu-1.0.2/sourcecpp_689c5adb8d/sourceCpp_14.so':
libaf.so.3: cannot open shared object file: No such file or directory
Unfortunately, I could not find an solution for my problem (even if some Stack Overflow questions raise issues which are more or less similar at first glance).
How can I fix it?