[Rcpp-devel] Rcpp build trouble with strings

Dirk Eddelbuettel edd at debian.org
Tue Aug 20 01:58:06 CEST 2013


Hi Jacob,

On 19 August 2013 at 13:10, jacob.a.russell.th at dartmouth.edu wrote:
| Hey again,
| 
| I built the default Rcpp.package.skeleton rcpp_hello_world to take in
| strings and it worked fine. My problems seem to be from the libraries
| themselves. I recompiled the libraries that I could to be shared
| libraries and now the package builds the .so file, but I still get an
| error when checking the package.
| 
| Error in dyn.load(file, DLLpath = DLLpath, ...) : 
|   unable to load shared object
|   '/home/jrussell/src/C++/NLP/RDGGDriver/SantosDartmouth.Rcheck/SantosDartmouth/libs/SantosDartmouth.so':
|     liblink_4_1b.so: cannot open shared object file: No such file or directory

Do you know about ldconfig and all that?  "Just linking" to a shared library
is usually not enough.

If all that is way too confusing, then don't build a library but rather
including all src/*.o directly into your package library -- R knows how to
find that.
| 
| The library liblink_4_1b.so is link grammar with slight modifications to
| work with C++ code instead of C code and doesn't have an R package. I
| have placed all libs in the src directory of the package, and they can
| all be found at build time, and the .so file seems to be correctly
| built, but then when it is checked, it seems not to use the same
| ldflags that it uses when building (PKG_LIBS). Is this something that I
| need to set separately? I have tried ??Makevars and google searches for
| "R Makevars" and "external libraries Rcpp" and not found much. Are there
| any concrete examples of packaging external libraries inside of R

Of course. For example RcppGSL has done it for years. Here GSL is assumed to
be a standard system library (but gsl-config --libs is queried to get the -L
argument). 

There are now 130 packages on CRAN that deploy Rcpp. Maybe you can find one
that suits your setup.

| packages? I have gone through all of the vignettes that I could find and
| can't seem to find anything about including pre-built .so files in
| packages. I suspect this is to keep source-only, but the libraries are
| not all mine and I don't have this option available.
| 
| Thanks!
| 
| Jacob Russell
| 
| P.S. Time-To-Response on this mailing list is probably the best that I
| have ever seen on a mailing list. Congrats!

:)

Had a busy day at work or else I would have replied earlier.

Dirk

| 
| On Fri, Aug 16, 2013 at 12:52:37PM -0500, Dirk Eddelbuettel wrote:
| > 
| > On 16 August 2013 at 13:45, jacob.a.russell.th at dartmouth.edu wrote:
| > | Hello,
| > | 
| > | I am trying to build a package but I have quite a few dependencies. As such, I
| > | have modified Makevars to be (I don't like backticks because I find them too
| > | similar to single quotes):
| > | 
| > | PKG_LIBS = $($(R_HOME)/bin/Rscript -e 'Rcpp:::LdFlags()') -L. -llink_4_1b -lDGG -lSTR -lDLL -lAF -lmy_std -lm
| > | PKG_CPPFLAGS=-I. -g
| > | 
| > | Which seems to compile when my R wrapper is (incorrectly):
| > | 
| > | RcppExport SEXP getDocGraph(std::string input){
| > |     
| > |     std::string testStr = input;
| > |     std::string output=getDG(testStr);
| > |     return(Rcpp::wrap(output));
| > | }
| > | 
| > | but then it gives me a segmentation fault because it cannot access the
| > | underlying character array (or general object) passed in by R.
| > | 
| > | Then if I change the function protoype to:
| > | 
| > | RcppExport SEXP getDocGraph(SEXP input){
| > |     
| > |     std::string testStr = Rcpp::as<std::string>(input);
| > |     std::string output=getDG(testStr);
| > |     return(Rcpp::wrap(output));
| > | }
| > | 
| > | it seems to compile, but when I go to check the package, the .Rcheck directory
| > | gives me an error:
| > | 
| > | ** testing if installed package can be loaded
| > | Error in dyn.load(file, DLLpath = DLLpath, ...) : 
| > |   unable to load shared object ...<packagename>.so':
| > | 
| > | and the .so file is not in the tgz package, but no error was given during
| > | compilation.
| > | 
| > | Any help is greatly appreciated.
| > 
| > Simplify. 
| > 
| > I would start by removing your six additional libraries and convince myself
| > that accessing a string via Rcpp works (and as our unit tests do that a lot,
| > you would have to be in a very unusual situation to not have it work).
| > 
| > Once that works, add your libraries. If and when things break again, examine
| > the differences.
| > 
| > 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