[SLL] linking - calling C++ code from Java using SWIG
Mathew D. Watson
watson at visiongate3d.com
Fri Nov 7 09:17:09 PST 2008
SWIG is awesome. I am amazed as I learn what it does, but the learning
curve has been steep. Yesterday I ran into a knot that I hope you folks
can help me untangle.
I have a java program that calls a c++ library from a separate project.
The command line is as follows, and the code runtime links against a
library I will call lib_abc.so that is sitting in the current directory.
$ java -Djava.library.path=. main
I originally got this error message.
java: symbol lookup error: undefined symbol: _Z8VVGCamera4open...
The symbol name was real long, and I saw it when I ran nm on the library
file. The library was created using
$ ld -r a.o b.o -o lib_ab.a
$ g++ -shared c.o -o lib_abc.so -L. -l_ab
I managed to eliminate the error by creating the .so using
$ g++ -shared a.o b.o c.o -o lib_abc.so
Can someone explain why the symbol was missing from the first library
and not from the second one? In particular, why did I get the error when
nm showed that the symbol was present?
How can I modify the first g++ line so it correctly links against the
static library lib_ab.a?
I am pretty sure the long symbol name is called a "mangled" name. Is
there a way to get nm to produce unmangled symbol names? Is there a
better tool that I can use to debug this sort of problem?
Mat
More information about the linux-list
mailing list