[Rcpp-devel] How to use external C++ libraries in R packages withRcpp.

Dirk Eddelbuettel edd at debian.org
Thu Sep 5 03:55:46 CEST 2013


On 5 September 2013 at 09:28, guxiaobo1982 wrote:
| I tried this
| 
| ## Use the R_HOME indirection to support installations of multiple R version
| PKG_CPPFLAGS=-I/opt/boost_1_54_0/include -I../inst/include
| PKG_LIBS=-L/opt/boost_1_54_0/lib -lboost_regex `$(R_HOME)/bin/Rscript -e
| "Rcpp:::LdFlags()"`
| 
| and this:
| 
|  
| 
| ## Use the R_HOME indirection to support installations of multiple R version
| PKG_CPPFLAGS=-I/opt/boost_1_54_0/include -I../inst/include
| PKG_LIBS = -L/opt/boost_1_54_0/lib -lboost_regex `$(R_HOME)/bin/Rscript -e
| "Rcpp:::LdFlags()"`
| 
|  
| 
| Still got
| 
|  
| 
| ** testing if installed package can be loaded
| Error in dyn.load(file, DLLpath = DLLpath, ...) :
|   unable to load shared object '/home/amber/R/x86_64-redhat-linux-gnu-library/
| 3.0/cpptest/libs/cpptest.so':
|   /home/amber/R/x86_64-redhat-linux-gnu-library/3.0/cpptest/libs/cpptest.so:
| undefined symbol: _ZTIN4Rcpp7RObjectE

You need to rebuild after you make that change.  Delete the .o and .so files
from below src/, try again.  

Send us the complete build output log from R CMD ..., ie the lines showing
how g++ is called to compile and (more importantly here) to link.  

Your linking goes wrong, somehow.

Dirk




| Error: loading failed
| Execution halted
| ERROR: loading failed
| * removing †/home/amber/R/x86_64-redhat-linux-gnu-library/3.0/cpptest†
| * restoring previous †/home/amber/R/x86_64-redhat-linux-gnu-library/3.0/
| cpptest†
| 
| Exited with status 1.
| 
|  
| 
| 
| 
| ------------------ Original ------------------
| From:  "Dirk Eddelbuettel"<edd at debian.org>;
| Date:  Sep 4, 2013
| To:  "guxiaobo1982"<guxiaobo1982 at qq.com>;
| Cc:  "Dirk Eddelbuettel"<edd at debian.org>; "rcpp-devel"
| <rcpp-devel at lists.r-forge.r-project.org>;
| Subject:  Re: [Rcpp-devel] How to use external C++ libraries in R packages
| withRcpp.
| 
| 
| On 4 September 2013 at 18:21, guxiaobo1982 wrote:
| | Hi Dirk,
| | 
| | Thanks for you help, here is wha I got in a test package:
| | 
| | 1.Rcpp.package.skeleton("cpptest")
| 
| Good start!
| 
| | 2. Add the following line to Makevars
| | 
| | PKG_CPPFLAGS=-I/opt/boost_1_54_0/include -I../inst/include PKG_LIBS = -L/opt/
| | boost_1_54_0/lib -lboost_regex `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
| 
| Those have to be __two distinct lines__ not one glued together. Try
| 
| PKG_CPPFLAGS=-I/opt/boost_1_54_0/include -I../inst/include
| PKG_LIBS = -L/opt/boost_1_54_0/lib -lboost_regex `$(R_HOME)/bin/Rscript -e
| "Rcpp:::LdFlags()"`
| 
| ie one assignment each to two variables PKG_CPPFLAGS and PKG_LIBS.
| 
| | 3. Change  rcpp_hello_world.cpp to this:
| 
| Looks good, and should work.  Boost Regex use is a nice small example.
| 
| Dirk
| 
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
| .

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list