UnsatisfiedLinkError (gxx and gcj) with JNI and C++ but not C
Andrew Richardson
a.chardson@gmail.com
Sun Feb 27 17:15:00 GMT 2011
Hi everyone,
I'm trying to resolve an UnsatisfiedLinkError with G++ when compiling a JNI binding. The binding was originally written *and verified* in C with 'gcc -std=gnu99'. I have tried modifying it slightly to be C++ and compiling with 'g++ -lstdc++' so I can easily interface with my desired C++ library. This builds without any problems, but upon running, I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/chardson/chardson/parallelsurf/lib/libparallelsurf.so: /home/chardson/chardson/parallelsurf/lib/libparallelsurf.so: undefined symbol: __gcj_personality_v0
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at parallelsurf.ParallelSURF.<clinit>(ParallelSURF.java:17)
at testpsurf.<init>(testpsurf.java:11)
at testpsurf.main(testpsurf.java:23)
Originally I got __gxx_personality_v0 instead of gcj, but I included the pragma for java_exceptions noted commonly online. I have tried searching extensively for a solution, but have not been successful. This post from 2002 to gcc-help simply claims the solution is linking to libstdc++, but my error does not change:
http://gcc.gnu.org/ml/gcc-help/2002-05/msg00286.html
Please note that I compile my source with:
g++ -Wall -g -lstdc++ -shared -O2 -c -fPIC -D_REENTRANT filename.cpp -I/usr/lib/jvm/java-6-openjdk/include/
and link with:
ld --shared filename.o -o libfilename.so
The header is of course created by 'javah -jni'
Also note that nm lists the __gcj_personality_v0 as undefined, but ever other symbol has one of the following types: daTWA
I was developing earlier on Ubuntu 10.04 but am now on a fresh copy of 10.10. My version of g++ is 4.4.5, ld is 2.20.51-system.20100908
Thanks sincerely for your help. This is driving me mad!
Andrew
More information about the Gcc-help
mailing list