如何调试linux中的java system.loadlibrary错误? [英] How to debug a java system.loadlibrary error in linux?

查看:1012
本文介绍了如何调试linux中的java system.loadlibrary错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java程序,通过JNI调用C代码,我试图在Linux上运行。外部代码由两个.so文件组成:一个用于JNI绑定(用swig构建),另一个用于实际的功能。我有两个库在同一个目录,并且LD_LIBRARY_PATH设置正确。 ldd从命令行运行时不会出现问题,但是当我在Eclipse编辑器中的运行配置对话框中将LD_LIBRARY_PATH设置为相同的值并尝试执行该程序时,会收到以下错误:



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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆