You are not logged in.
I'm experimenting with the Java AWT native interface. My project (which so far is a near clone of the code in the Sun tutorial) compiles and links without a problem:
[corey@sariss jstuff]$ ls
MANIFEST.MF Makefile MyCanvas.c MyCanvas.h MyCanvas.java
[corey@sariss jstuff]$ make
cc -ansi -fPIC -shared -Wall -Wpointer-arith -MM -MP -MT "MyCanvas.o MyCanvas.d" -o MyCanvas.d MyCanvas.c
javac -Xlint:deprecation MyCanvas.java
cc -ansi -fPIC -shared -Wall -Wpointer-arith -c -o MyCanvas.o MyCanvas.c
cc -ansi -fPIC -shared -Wall -Wpointer-arith -Wl,-soname,libMyCanvas.so -o libMyCanvas.so MyCanvas.o -lawt -ljava -ljvm -lverify -lX11
jar cfm test.jar MANIFEST.MF *.class libMyCanvas.so
[corey@sariss jstuff]$ ls
MANIFEST.MF MyCanvas$1.class MyCanvas.class MyCanvas.h MyCanvas.o test.jar
Makefile MyCanvas.c MyCanvas.d MyCanvas.java libMyCanvas.so
Yet when I try to run it, it seems as though it doesn't load libawt:
corey@sariss jstuff]$ java -jar test.jar
java: symbol lookup error: /home/corey/src/jstuff/libMyCanvas.so: undefined symbol: JAWT_GetAWT
So I try `ldd` to ensure that my shared object linked correctly and that my LD_LIBRARY_PATH environment variable is good:
corey@sariss jstuff]$ ldd libMyCanvas.so
linux-vdso.so.1 => (0x00007fff7a5ff000)
libawt.so => /opt/java/jre/lib/amd64/libawt.so (0x00007fef154bd000)
libjava.so => /opt/java/jre/lib/amd64/libjava.so (0x00007fef1538e000)
libjvm.so => /opt/java/jre/lib/amd64/server/libjvm.so (0x00007fef148ab000)
libverify.so => /opt/java/jre/lib/amd64/libverify.so (0x00007fef1479c000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x00007fef14440000)
libc.so.6 => /lib/libc.so.6 (0x00007fef140e3000)
libm.so.6 => /lib/libm.so.6 (0x00007fef13e61000)
libdl.so.2 => /lib/libdl.so.2 (0x00007fef13c5d000)
libnsl.so.1 => /lib/libnsl.so.1 (0x00007fef13a44000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007fef13827000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007fef1360c000)
/lib/ld-linux-x86-64.so.2 (0x00007fef1588e000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00007fef13409000)
libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007fef13204000)
Looks fine to me. Any JNI experts here who can shed some light on this?
Thanks.
Last edited by cmtptr (2011-01-20 03:31:02)
Offline
So after three days of messing around with LD_PRELOAD and library paths, Googling like a madman, and banging my head against the wall over this, I just discovered that I was linking against libawt.so instead of libjawt.so. Unfortunately there is a libawt.so, so I didn't get a "library not found" error as a hint.
Offline