[Rcpp-devel] Linking problem when wrapping a armadillo-based C++ library in a R package using RcppArmadillo
edd at debian.org
Wed Jul 25 17:57:03 CEST 2018
On 25 July 2018 at 17:30, julien chiquet wrote:
| I am trying to wrap the optim library (https://github.com/kthohr/optim) in
| R via an R package using Rcpp/RcppArmadillo. Indeed, optim relies on
| armadillo itself. The github repository can be found here
| To do that, I put the headers of optim into inst/include/ and the cpp files
| into src/. Then I tried to "heuristically" pull everything together in the
| src/Makevars files, after my (obviously poor) understanding of the R manual
| pages about Makevars and from the various examples that I copied from the
| web (especially from the RcppMLPACK1 which, relies on the C++ library
| MLPACK, itself based on armadillo
| The package installation (including compilation of optim) successes (at
| least, the package can be installed). Then I tried to create two small Rcpp
| functions for two examples available in the original optim library,
| starting with the following lines
| // [[Rcpp::depends(RcppArmadillo)]]// [[Rcpp::plugins(cpp11)]]
| #define USE_RCPP_ARMADILLO
| #include "optim.hpp"
| (The #define command is an option of the optim library.)
| However, when I call the corresponding R functions, I get the following
| Armadillo errors in R which I do not have when running them in 'pure' C++
| (I am pretty sure it is not a syntax problem, the Rcpp code and the
| original C++ code are hopefully identical, except for the headers).
| > library(optimLibR)> ackley_function()error: arma::memory::acquire(): out of memory
| > library(optimLibR)> logit_optimLib()error: Mat::init(): requested size is not compatible with column vector layout
| So it seems to me that the header of armadillo are correctly defined but I
| am not sure that I reach the src (cpp) part of armadillo which is required
| at the execution.
| If anyone can confirm or help pointing the origin of the error, I would be
| Thanks for your time,
Good news / bad news. I think the good news is that everything builds, so you
have no linking issue. In fact, no RcppArmadillo package links to Armadillo
as we do everything via the headers.
But you seem to have run-time issues which _could_ stem from the fact that
RcppArmadillo sets a bunch of #define variables and your use may be slightly
different / conflict with these. Maybe you can check with Keith about how
his optim(lib) could / should be called from R.
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel