On 14.09.2018 05:17, Simon Woodward wrote: > I am developing a simulation model in C++ and I want to expose it to R for > testing. The model is in a C++ class and uses the boost::odeint library for > numerical integration. I am also using an unordered_map to expose the model > variables to the user. > I am having some trouble exposing the class functionality to C++, either as > separate // [[Rcpp::export]] methods or using RCPP_MODULE. The following code > successfully instantiates the model and returns the unordered_map but crashes > Rcpp if I try to access the advance(t,dt) method.
What do you mean with "crashes Rcpp"? On my system it mearly gives a compiler error: /usr/include/c++/6/bits/stl_iterator_base_funcs.h: In instantiation of ‘void std::advance(_InputIterator&, _Distance) [with _InputIterator = Rcpp::InputParameter<double>; _Distance = Rcpp::InputParameter<double>]’: > # sample code embedded in an R script With the given ratio of C++ to R code it would have been better to use a C++ file with R code embedded via /*** R ... */. > library(Rcpp) > > Sys.setenv("PKG_CXXFLAGS"='-I"C:/boost/boost_1_66_0"') The BH package can help with that: // [[Rcpp::depends(BH)]] > sourceCpp(code=' > #include <unordered_map> > #include <string> > #define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE > #include <boost/numeric/odeint.hpp> > #include <Rcpp.h> > > // Enable C++11 via this plugin (Rcpp 0.10.3 or later) > // [[Rcpp::plugins(cpp11)]] > > using namespace std; The above quoted error message indicates that your advance method and std::advance are getting mixed up. Remove this "using namespace std;" and handle to resulting errors by using "std::" or "using std::...;". BTW, for larger pieces of code I would also get rid of "using namespace Rcpp;". cheerio ralf -- Ralf Stubner Senior Software Engineer / Trainer daqana GmbH Dortustraße 48 14467 Potsdam T: +49 331 23 61 93 11 F: +49 331 23 61 93 90 M: +49 162 20 91 196 Mail: ralf.stub...@daqana.com Sitz: Potsdam Register: AG Potsdam HRB 27966 P Ust.-IdNr.: DE300072622 Geschäftsführer: Prof. Dr. Dr. Karl-Kuno Kunze
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel