問題解決。 libjnidiagnosticsserver.so缺少鏈接器lib和libfesdiagnosticsserver.so的路徑。查找未定義符號的Java 1.4必須比Java 1.6更加寬鬆。感謝大家的幫助。任何關於禮儀的建議是否公平地結束?Java版本1.6加載共享庫的UnsatisfiedLinkError,Java 1.4正常工作?
(免責聲明:Java的新手)
我寫了使用JNI調用我的C++共享庫的Java應用程序。它打印java版本並在執行時獲取並打印LD_LIBRARY_PATH。
Java版本1.4 - 所有這些都是好的!:
/usr/bin/java -jar "javadiagnosticsserver-test.jar"
java version=1.4.2
LD_LIBRARY_PATH = /usr/lib/fesdiagnostics
Java版本1.6 - UnsatisfiedLinkError:
的 「未定義的符號」 _ZN17DiagnosticsServerC1Ev在libfesdiagnosticsserver定義。所以。 Java 1.4認爲它,Java 1.6不? System.loadLibrary(「fesdiagnosticsserver」)調用起作用。 Java 1.6的loadLibrary不知道在哪裏看?
/usr/java/jdk1.6.0_26/bin/java -jar "javadiagnosticsserver-test.jar"
version=1.6.0_26
class path=javadiagnosticsserver-test.jar
os.arch=i386
sun.arch.data.model=32
$HOME = /home/esutton
$LD_LIBRARY_PATH = /usr/java/jdk1.6.0_26/jre/lib/i386/client:/usr/java/jdk1.6.0_26/jre/lib/i386:/usr/java/jdk1.6.0_26/jre/../lib/i386:/usr/lib/fesdiagnostics
Dbg: Loading native lib dependencies...
Dbg: System.loadLibrary("fesdiagnostics");
Dbg: loaded fesdiagnostics
Dbg: The undefined symbol _ZN17DiagnosticsServerC1Ev is in libfesdiagnosticsserver.so
Dbg: System.loadLibrary("fesdiagnosticsserver");
Dbg: loaded fesdiagnosticsserver
Dbg: System.loadLibrary("jnidiagnosticsserver");
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/fesdiagnostics/libjnidiagnosticsserver.so: /usr/lib/fesdiagnostics/libjnidiagnosticsserver.so: undefined symbol: _ZN17DiagnosticsServerC1Ev
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at fes.JniDiagnostics.libLoad(JniDiagnostics.java:30)
at fes.JniDiagnostics.<clinit>(JniDiagnostics.java:38)
at fes.FesDiagnostics.<clinit>(FesDiagnostics.java:17)
at javadiagnosticsservertest.Main.main(Main.java:37)
環境是在兩種情況下是相同的:
LD_LIBRARY_PATH =/usr/lib/fesdiagnostics
PATH = /opt/ActivePython-2.7/bin:/usr/java/jdk1.6.0_26/bin: \
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin: \
/sbin:/opt/qtsdk-2010.01/qt/bin:/home/esutton/bin:/sbin: \
/opt/qtsdk-2010.01/qt/bin
JAVA_HOME = /usr/java/jdk1.6.0_26
本地C++的共享庫的編譯選項:
g++ -Wl,-rpath,/opt/qtsdk-2010.01/qt/lib -shared \
-Wl,-soname,libjnidiagnosticsserver.so.1 \
-o libjnidiagnosticsserver.so.1.0.0 build/Debug/GNU-Linux-x86/ \
jnifesdiagnostics.o -L/opt/qtsdk-2010.01/qt/lib -lQtGui \
-L/opt/qtsdk-2010.01/qt/lib -L/usr/X11R6/lib -lQtCore -lpthread
ln -s libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so
ln -s libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so.1
ln -s libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so.1.0
rm -f dist/libjnidiagnosticsserver.so.1.0.0
rm -f dist/libjnidiagnosticsserver.so
rm -f dist/libjnidiagnosticsserver.so.1
rm -f dist/libjnidiagnosticsserver.so.1.0
mv -f libjnidiagnosticsserver.so.1.0.0 libjnidiagnosticsserver.so \
\libjnidiagnosticsserver.so.1 libjnidiagnosticsserver.so.1.0 dist/
當它工作的Java 1.4下,我必須加載jnidiagnosticsserver的依賴第一。我不懂爲什麼。我預計LD_LIBRARY_PATH會照顧到這一點:
public class JniDiagnostics {
public native void open(String configurationFile);
public native void close();
public native String query(String restfulQueryString);
private static String[] libraryDependencyList = {"fesdiagnostics", "fesdiagnosticsserver", "jnidiagnosticsserver"};
private static void libLoad(String libName) {
System.out.println("Dbg: System.loadLibrary(\"" + libName + "\");");
System.loadLibrary(libName);
System.out.println("Dbg: loaded " + libName);
}
static //static initializer code
{
System.out.println("Dbg: Loading native lib dependencies...");
for (int i = 0; i < libraryDependencyList.length; i++) {
libLoad(libraryDependencyList[i]);
}
}
}
安全問題? Java版本配置問題?
預先感謝任何方向,
-Ed
CentOS 5.2 32-bit
Netbeans 6.9.1
Java version 1.6.0_26
PS:我的目標是讓我的Java源在Glassfish的RESTful網絡服務 運行。如果LD_LIBRARY_PATH可以解決的Java應用程序,我希望同 解決方案將Glassfish的3
你可以嘗試啓動VM'的java -Djava.library.path =/usr/lib目錄/ fesdiagnostics ...' – stacker 2012-02-21 16:45:58
感謝堆快速回復。添加java.library。路徑似乎沒有影響:/usr/java/jdk1.6.0_26/bin/java -Djava.library.path =/usr/lib/fesdiagnostics -jar「javadiagnosticsserver-test.jar」 – 2012-02-21 16:47:56
@Ed。:你正在編譯有任何選項的C++庫? – Cratylus 2012-02-21 16:51:21