SUSE Linux Java Calling gcc C fails with undefined symbol

java TempCalcJava

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

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).


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


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.

W B Langdon 9 Dec 2006