SUSE Linux Java Calling gcc C fails with undefined symbol

java TempCalcJava

Exception in thread "main" java.lang.UnsatisfiedLinkError: /ufs/servh06/users/wlangdon/temp/libTempCalcJava.so: ./tempCalcRoutines.so: undefined symbol: _Znaj
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1473)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1397)
        at java.lang.Runtime.loadLibrary0(Runtime.java:788)
        at java.lang.System.loadLibrary(System.java:832)
        at TempCalcJava.<clinit>(TempCalcJava.java:115)

Based on code from Chris Anderson

The problem is easily fixed by replacing -lC (ie building .so files with C library) with -lstdc++ (building .so files with C++ library).

-shared

The GNU cpp compiler expects -shared instead of -G.

LD_LIBRARY_PATH

You have probably remembered to include the directory containing the .so files in your library path. If not, something like the following may do the trick.
setenv LD_LIBRARY_PATH .:$LD_LIBRARY_PATH


W B Langdon 9 Dec 2006