gpt4 book ai didi

加载共享库时 Java 1.6 版 UnsatisfiedLinkError,Java 1.4 工作正常吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:23:19 25 4
gpt4 key购买 nike

问题解决了。 libjnidiagnosticsserver.so 缺少链接器库和 libfesdiagnosticsserver.so 的路径。 Java 1.4 在定位 undefined symbol 方面必须比 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:

undefined symbol _ZN17DiagnosticsServerC1Evlibfesdiagnosticsserver.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++ 共享库编译选项:

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版本配置问题?

提前感谢您的指导,

-埃德

CentOS 5.2 32-bit
Netbeans 6.9.1
Java version 1.6.0_26

PS: My goal is to get my Java source to run in a Glassfish RESTful web service. If LD_LIBRARY_PATH can be solved for a java app, I am hoping the same solution will apply under Glassfish 3.

最佳答案

我想问题出在您的共享库的 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.

关于加载共享库时 Java 1.6 版 UnsatisfiedLinkError,Java 1.4 工作正常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9381385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com