[R] linking other C++ libraries

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 26 19:09:29 CET 2004


On Thu, 26 Feb 2004, Sundar Dorai-Raj wrote:

> 
> Samuel Kemp wrote:
> 
> > Hi,
> > 
> > I have written a little C++ program, which uses a third party library 
> > called ANN (approximate nearest neighbours)....
> > 
> > #include "/home/sekemp/ann_0.2/include/ANN/ANN.h"
> > 
> > I have tried R CMD SHLIB ann.h myProgram.cc, although this compiles when 
> > I load it into R I get the following message..
> > 
> > dyn.load("/home/sekemp/ann_0.2/ann.so")
> > Error in dyn.load(x, as.logical(local), as.logical(now)) :
> >        unable to load shared library "/home/sekemp/ann_0.2/GammaTest.so":
> >  /home/sekemp/ann_0.2/GammaTest.so: undefined symbol: 
> > _ZN10ANNkd_treeC1EPPdiii12ANNsplitRule
> > 
> > I get the same error when I dyn.load the myProgram.so aswell.
> > 
> > There is nothing wrong with the ann library as I have used it directly 
> > in C++ using the compiler-linker thingy....
> > 
> > g++ myProgram.cc -I/home/sekemp/ann_0.2/include 
> > -L/home/sekemp/ann_0.2/lib -lANN
> > 
> > Does anyone have any ideas?
> > 
> 
> Looks like C++ name mangling. Did you wrap your code in extern "C" {}?

Yes, but there is a missing library with the mangled symbol (which 
contains `ANN').  It needs to be

   R CMD SHLIB ann.h myProgram.cc -L/home/sekemp/ann_0.2/lib -lANN

I believe, if the .h file really is to be compiled ....

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list