I have some running c++ code using the Lapacke
version that comes with OpenBlas
. I would like to include this code into an R package and transfer data between that function and R using the Rcpp
package. But somehow the two seem not to like each other. As soon as I have #include <lapacke.h>
and #include <Rcpp.h>
in one source file it isn't compiling anymore. Both separately work fine. There is a whole bunch off error messages which as far as I can tell say that Rcpp
is broken (e.g /home/Alex/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/traits/traits.h:32:15: error: expected ‘)’ before ‘__extension__’)
.
I have no idea why this happens. Is there a way to use both at the same time? Or should I do something completely different?
Here is a minimal example that gives me the error:
I created a package using
Rcpp::Rcpp.package.skeleton("LT", example_code = FALSE)
I added a
.cpp
file to/src
containing#include <lapacke.h> #include <Rcpp.h> int test_LAPACK(){ return(1); }
I added a Makvars file to
/src
containingPKG_CXXFLAGS = -I/opt/OpenBLAS/include PKG_LIBS = -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran CXX_STD = CXX11
Compile and install
Rcpp::compileAttributes("LT") devtools::install("LT")
It actually works on my system following a standard
sudo apt install liblapacke-dev
provided I also change the include order.Witness:
Source
Build
Install
Run
(After I added a line
// [[Rcpp::export]]
, rancompileAtttributes()
and rebuilt and installed.)Summary
Check your compiler. There is no fundamental reason this should not work, and it works here (Ubuntu 18.04).