问题解决了。 libjnidiagnosticsserver.so缺少链接器lib和libfesdiagnosticsserver.so的路径。 Java 1.4在定位未定义的符号时必须比Java 1.6更自由。感谢大家的帮助。关于礼节的任何建议都要公平地解决这个问题吗?
(免责声明:Java新手)
我写了一个Java应用程序,它使用JNI来调用我的C ++共享库。它打印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.so 中定义。 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
Native C ++ Shared Lib Compile Options:
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 Web中运行 服务。如果可以为java应用程序解决LD_LIBRARY_PATH,我希望同样如此 解决方案将适用于Glassfish 3。
答案 0 :(得分:4)
我猜问题是你的共享库的missig依赖。尝试运行以下命令来解决这个问题:
ldd -d -r /home/esutton/jnidiagnosticsserver/dist/libjnidiagnosticsserver.so.1.0.0
这显示缺少的符号。
UnsatisfiedLinkError
记录为:
Thrown if the Java Virtual Machine cannot find an appropriate
native-language definition of a method declared native.