如何调试linux中的java system.loadlibrary错误? [英] How to debug a java system.loadlibrary error in linux?
问题描述
java.lang.UnsatisfiedLinkError:[路径到库] / [JNI绑定库] .so:[实际代码库] .so:无法打开共享对象文件:没有这样的文件或目录
这使我相信JNI包装库已成功加载,但是当该库尝试加载包含实际代码的库时,会出现故障。有没有办法进一步调试?
我将进一步注意到,这个问题发生在eclipse编辑器本身,我没有尝试将代码打包一个jar并在一个独立的jvm实例中运行它。
我认为问题是调用System.loadLibrary (String)并使用LD_LIBRARY_PATH。使用loadLibrary(foo)将在您的java.library.path中查找名为libfoo.so的内容。如果没有找到任何名为libfoo.so的文件,您将收到此错误。
现在,如果您只是设置了LD_LIBRARY_PATH,您想要的本机符号将自动被链接器,所以你不需要设置-Djava.library.path。
根据我在gdal项目中swig的经验,这个错误实际上是无害的,因为LD_LIBRARY_PATH被设置,这将工作正常。
我建议使用-Djava.library.path并且明确地调用loadLibrary,原因是如果你决定使用webstart部署您的应用程序,您将显式地需要调用loadLibrary来获取您的本机库。
当我使用eclipse时,请按照Daff给出的说明进行编辑构建路径中库选项卡下的jar下的本地库。再次提到,这只是在封面下设置java.library.path。
I have a Java program that is calling C code through JNI that I'm attempting to run on Linux. The external code consists of two .so files: one for the JNI bindings (built with swig) and the other with the actual functions. I have the two libraries in the same directory and LD_LIBRARY_PATH is set correctly. ldd reports no problems when running from the command line, but when I set the LD_LIBRARY_PATH to the same value in the "run configurations" dialog in the Eclipse editor and attempt to execute the program, it gets the following error:
java.lang.UnsatisfiedLinkError: [path to libraries]/[JNI binding library].so: [actual code library].so: cannot open shared object file: No such file or directory
This leads me to believe that the JNI wrapper library is loaded successfully, but there is a failure when that library attempts to load the library containing the actual code. Is there any way to debug this further?
I will further note that this problem is happening in the eclipse editor itself and that I haven't attempted to package the code into a jar and run it within a free-standing jvm instance.
I think the issue is with the call to System.loadLibrary(String) and using LD_LIBRARY_PATH. Using loadLibrary("foo") will look in your java.library.path for something named libfoo.so. If nothing named libfoo.so is found you will get this error.
Now if you just set up the LD_LIBRARY_PATH, the native symbols you want will automatically be picked up by the linker, so you don't need to set up -Djava.library.path.
In my experience with swig in the gdal project, this error is actually harmless and since the LD_LIBRARY_PATH is set up, this will work fine.
I would recommend using -Djava.library.path and calling loadLibrary explitly, the reason being that if you ever decide to deploy your app with webstart, you will explicitly need to call loadLibrary to get your native libs picked up.
When I use eclipse I follow the instructions that Daff gave where you edit the native library under the jar in the Libraries tab in the Build Path. Just to mention again, this just sets java.library.path under the covers.
这篇关于如何调试linux中的java system.loadlibrary错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!