Skip to content
Prev 6340 / 10988 Next

[Rcpp-devel] Rcpp build trouble with strings

Hey Dirk,

I know that linking to a shared library is not enough, and that I need
to runtime load the actual libraries that have their shared code stored
separately. I wanted to do this in a way that when loaded by someone who
installs the package, the shared libraries that I am including are
available and the installer does the work for setting the ldconfig path
for the libraries themselves. I looked at the RcppGSL package, but it
doesn't actually include the library itself, but rather has you install
it from an external source. I would like to include the libraries
themselves, as they are not available from an external source. I settled
on trying to include just the object files themselves (extracted them
from the archives, they are all compiled with -fPIC). This got rid of
the error that it can't find my shared library (obviously) but still has
an error that it cannot find the symbols for one of the files that was
in one of the libraries. 

Running the default build I get an error:

Error in dyn.load....
...undefined symbol:_Z20parse_options_createv

This is a function in a file that I only have an object for and not a
cpp file (api.h and api.o)

Because I kept getting this error, I tried to add a target to Makevars
to see if I could override the build options for only the
SantosDartmouth.so file that I am trying to create. I created the build
target (Note: $OBJS is a variable that I hand-made with ls *.o):

SantosDartmouth.so: $(OBJECTS)
        $(CC) -shared $(PKG_LIBS) $(PKG_CPPFLAGS) $(OBJS) -Wl,--no-undefined -o SantosDartmouth.so

I got the same error, and the output of R CMD check SantosDartmouth was
the same except that it output that it overrode my target and showed
what it actually used to compile. So from the command line, I ran what I
actually wanted to run to build the target.

g++ -shared `Rscript -e 'Rcpp:::LdFlags()'` `Rscript -e
'Rcpp:::CxxFlags()'` analyze-linkage.o and.o api.o build-disjuncts.o
command-line.o constituents.o count.o DG_commonTypes.o
DGG_graphComponents.o DGG_heuristics.o DGG_strings.o DGG_templates.o
DGG_tree.o DG_objectTable.o diGraph.o DLL_commonTypes.o
documentGraphGenerator.o error.o extract-links.o fast-match.o
functions.o getDocGraph.o idiom.o linkset.o massage.o my_std.o parse.o
post-process.o pp_knowledge.o pp_lexer.o pp_linkset.o preparation.o
print.o print-util.o prune.o read-dict.o resources.o skip_exp.o
string-set.o stringTable.o tokenize.o utilities.o word-file.o -o
SantosDartmouth.so

Then I was able to load this in R with dyn.load("SantosDartmouth.so")
and sourcing my R file in the R directory of my package, I could run the
function. However, I would still like to be able to build the package
and not manually distribute this. How can I force the package to accept
my override for this target?

Thanks again, sorry to be so long winded.

Jacob
On Mon, Aug 19, 2013 at 06:58:06PM -0500, Dirk Eddelbuettel wrote: