[Rcpp-devel] Linking problem when wrapping a armadillo-based C++ library in a R package using RcppArmadillo
julien.chiquet at gmail.com
Wed Jul 25 21:12:24 CEST 2018
Great ! And no hurry.
mel: julien.chiquet at inra.fr
tel: +33(0)1 44 08 16 73
On Wed, Jul 25, 2018 at 7:12 PM Keith O'Hara <kth.ohr at gmail.com> wrote:
> I’m traveling without my laptop this week. I’ll take a look at the error
> when I return.
> On Jul 25, 2018, at 12:26 PM, julien chiquet <julien.chiquet at gmail.com>
> On Wed, Jul 25, 2018 at 5:57 PM Dirk Eddelbuettel <edd at debian.org> wrote:
>> On 25 July 2018 at 17:30, julien chiquet wrote:
>> | Hi,
>> | I am trying to wrap the optim library (https://github.com/kthohr/optim)
>> | R via an R package using Rcpp/RcppArmadillo. Indeed, optim relies on
>> | armadillo itself. The github repository can be found here
>> | https://github.com/jchiquet/optimLibR
>> | To do that, I put the headers of optim into inst/include/ and the cpp
>> | into src/. Then I tried to "heuristically" pull everything together in
>> | src/Makevars files, after my (obviously poor) understanding of the R
>> | pages about Makevars and from the various examples that I copied from
>> | web (especially from the RcppMLPACK1 which, relies on the C++ library
>> | MLPACK, itself based on armadillo
>> | https://github.com/rcppmlpack/RcppMLPACK1/blob/master/src/Makevars).
>> | The package installation (including compilation of optim) successes (at
>> | least, the package can be installed). Then I tried to create two small
>> | 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'
>> | (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
>> | at the execution.
>> | If anyone can confirm or help pointing the origin of the error, I would
>> | debtful...
>> | Thanks for your time,
>> Good news / bad news. I think the good news is that everything builds, so
>> have no linking issue. In fact, no RcppArmadillo package links to
>> 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
>> different / conflict with these. Maybe you can check with Keith about how
>> his optim(lib) could / should be called from R.
> Thanks for your prompt and helpful answer. At least I know I do not have
> to struggle with the Makevars.
> I'll check with Keith.
>> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rcpp-devel