Linux 中的 java.lang.UnsatisfiedLinkError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/538886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:58:53  来源:igfitidea点击:

java.lang.UnsatisfiedLinkError in Linux

javalinuxjava-native-interfacenative

提问by OscarRyz

I've managed to get into a linux machine to try the HotKey library suggested in this answer.

我已经设法进入一台 linux 机器来尝试这个答案中建议的 HotKey 库

I've compiled the sample code and now I run the program and I've got the following message:

我已经编译了示例代码,现在我运行了程序,我收到了以下消息:

[oracle@machine jxgrabkey-0.2.1_i386]$ java -classpath lib/JXGrabKey.jar:Example JXGrabKeyTest

Exception in thread "main" **java.lang.UnsatisfiedLinkError:** /home/oracle/javasample/jxgrabkey-0.2.1_i386/lib/libJXGrabKey.so: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /home/oracle/javasample/jxgrabkey-0.2.1_i386/lib/libJXGrabKey.so)
   at java.lang.Runtime._load(libgcj.so.7rh)
   at java.lang.Runtime.load(libgcj.so.7rh)
   at java.lang.System.load(libgcj.so.7rh)
   at JXGrabKeyTest.main(JXGrabKeyTest.java:17)

I know how to handle this in Windows ( just by adding the DLL to the PATH env var ) but I'm not that sure about linux.

我知道如何在 Windows 中处理这个问题(只需将 DLL 添加到 PATH env var ),但我对 linux 不太确定。

I've read something about LD_LIBRARY_PATH and some other env vars but I can make it work.

我已经阅读了一些关于 LD_LIBRARY_PATH 和其他一些环境变量的内容,但我可以让它工作。

Any advice?

有什么建议吗?

EDIT

编辑

After the support from mmyers to indentify the problem and reading this threadand this other.

在 mmyers 的支持下确定问题并阅读此线程此其他线程之后

I can tell:

我可以告诉:

My system is: Linux 2.6.18-53.el5

我的系统是:Linux 2.6.18-53.el5

My GCC version(s) is ( are) :

我的 GCC 版本是(是):

gcc-c++-4.1.2-14.el5

gcc-c++-4.1.2-14.el5

gcc-gfortran-4.1.2-14.el5

gcc-gfortran-4.1.2-14.el5

libgcc-4.1.2-14.el5

libgcc-4.1.2-14.el5

gcc-4.1.2-14.el5

gcc-4.1.2-14.el5

The problems is I require gcc 4.2.0

问题是我需要 gcc 4.2.0

Aaand apparently there is no gcc 4.2.0 for my system.

Aaand 显然我的系统没有 gcc 4.2.0。

I guess I would have to wait for it to come or the author recompile it in a previous version.

我想我将不得不等待它出现或作者在以前的版本中重新编译它。

mmyers, thanks a lot for your help.

mmyers,非常感谢您的帮助。

采纳答案by Michael Myers

Did you try -Djava.library.path=/path/to/library?

你试了-Djava.library.path=/path/to/library吗?

EDIT:Re-reading the error message, it looks to me that the native library you're loading is trying to link to glibc version 3.4.9, which apparently is not installed. Can you check what version of glibc you have? What Linux distro are you running?

编辑:重新阅读错误消息,在我看来,您正在加载的本机库正试图链接到 glibc 3.4.9 版,该版本显然未安装。你能检查一下你有什么版本的glibc吗?你在运行什么 Linux 发行版?

EDIT2:The problem seems to be narrowed down to libstdc++. I'm about to the edge of my knowledge, but this threadmight be useful. It suggests upgrading to gcc 4.2; from the comments, you appear to have version 4.1.2. Let me know if that doesn't work.

EDIT2:问题似乎缩小到 libstdc++。我即将达到我的知识边缘,但这个线程可能有用。它建议升级到 gcc 4.2;从评论来看,您似乎拥有 4.1.2 版。如果这不起作用,请告诉我。

回答by subes

subes, JXGrabKey dev here ...

subes,JXGrabKey 开发者在这里...

I don't know much about this error myself, but your lead about gcc and/or libstdc++ should be right

我自己对这个错误不太了解,但你对 gcc 和/或 libstdc++ 的引导应该是正确的

Personally I am using the gcc version shipped with Ubuntu 8.10 atm. I always stick to the latest version shipped.

我个人使用的是 Ubuntu 8.10 atm 附带的 gcc 版本。我总是坚持使用最新发布的版本。

Current version: g++ (Ubuntu 4.3.2-1ubuntu12) 4.3.2

当前版本:g++ (Ubuntu 4.3.2-1ubuntu12) 4.3.2

The following libstdc++ packages are installed on my machine: http://packages.ubuntu.com/intrepid/libstdc++5http://packages.ubuntu.com/intrepid/libstdc++6

我的机器上安装了以下 libstdc++ 包:http: //packages.ubuntu.com/intrepid/libstdc++5 http://packages.ubuntu.com/intrepid/libstdc++6

Hope this helps, if you find anything useful, tell me. :) Maybe i have to compile jxgrabkey with an older version of gcc for releases, so it is downwards compatible? Does anyone have a wise advice? ^^

希望这会有所帮助,如果您发现任何有用的信息,请告诉我。:) 也许我必须用旧版本的 gcc 编译 jxgrabkey 才能发布,所以它向下兼容?有没有人有明智的建议?^^