java.lang.UnsatisfiedLinkError: com.example.program.ClassName.foo()L

huangapple go评论63阅读模式
英文:

java.lang.UnsatisfiedLinkError: com.example.program.ClassName.foo()L

问题

我无法运行库的方法。
我的库在我的PATH中,并且通过以下代码加载时也没有出错:

System.loadLibrary("FTDIInterface");

但是函数不起作用。
我得到以下异常:

Caused by: java.lang.UnsatisfiedLinkError: Messgeraet.src.net.sf.yad2xx.FTDIInterface.getDevices()[LMessgeraet/src/net/sf/yad2xx/Device;
在Messgeraet.src.net.sf.yad2xx.FTDIInterface.getDevices(Native Method)
在Messgeraet.src.Emu.EmuConnection.(EmuConnection.java:22)
在Messgeraet.src.Emu.EmuModel.connect(EmuModel.java:27)
在Messgeraet.src.JavaFX.FXController.connect(FXController.java:112)
... 62 more

我正在使用Eclipse。在IntelliJ中,它正常工作,我还有另一个Eclipse项目,可以无问题地包含该库。

为什么无法运行我的方法FTDIInterface.getDevices?

英文:

I can't run methods of a library.
My library is in my PATH and also getting loaded without errors by following code:

	System.loadLibrary("FTDIInterface");

But the functions are not working.
I get the following exception:

Caused by: java.lang.UnsatisfiedLinkError: Messgeraet.src.net.sf.yad2xx.FTDIInterface.getDevices()[LMessgeraet/src/net/sf/yad2xx/Device;
at Messgeraet.src.net.sf.yad2xx.FTDIInterface.getDevices(Native Method)
at Messgeraet.src.Emu.EmuConnection.<init>(EmuConnection.java:22)
at Messgeraet.src.Emu.EmuModel.connect(EmuModel.java:27)
at Messgeraet.src.JavaFX.FXController.connect(FXController.java:112)
... 62 more

I am using eclipse. In IntelliJ it is working fine and I also got another eclipse project that includes the library without any problems.

Why it can't run my method FTDIInterface.getDevices?

答案1

得分: 1

I will provide the translated version of the text you provided. Here it is:

你的包似乎有些问题;Messgereat.src 听起来像是你有一个名为 Messgereat 的项目目录,在其中有一个名为 'src' 的文件夹包含你的 Java 源代码,并且你的构建工具配置出现了问题;正确的包名应该是:package net.sf.yad2xx;,但由于构建配置错误,它未能正常工作,于是你决定通过更新 package 语句来修复问题,但却破坏了你的 JNI 绑定。

解决方案是撤销你对包语句所做的所有更改,并修复你的构建脚本。

或者,如果你真的打算使用那个奇怪的包名,那么请确保你已经使用完全相同的构建设置执行了 javah,并将其作为你 JNI 代码的基础。如果你已经这样做了,请像 @user2543253 所建议的那样,在库中包含导出的符号。

注意:你的 loadLibrary 调用实际上工作有些奇怪;PATH 与此无关,但可能你的库恰好位于列在你库路径上的地方,这是名为 java.library.path 的系统属性(虚拟机的属性,而不是你的操作系统的属性);你可以使用以下方式设置它:

java -Djava.library.path=/path1:/path2 -cp /path/to/dep1.jar:/path/to/dep2.jar com.foo.Main

由于这种混淆,也有可能加载了一些不同的名为 FTDIInterface 的本地库文件,而不是你认为加载的那个。如果你想确保加载了什么内容,运行 System.load("/absolute/path/to/the/dll-jnilib-or-so-libraryfile.so"); - 这样你就能确定了。

英文:

Your package seems off; Messgereat.src sounds like you have a project dir named Messgereat, within you have a folder named 'src' with your java sources, and you've misconfigured your build tooling; the right package name sounds like it should be: package net.sf.yad2xx;, but due to a misconfigured build it wasn't working and you decided to fix the problem by updating your package statements, but that broke your JNI bindings.

The solution would then be to undo all the changes you've made to your package statements, and fix your build script instead.

Alternatively, if you really do intend to use that bizarre package, then make sure you have executed javah with the exact same build setup and use that as a basis for your JNI code. If you've done that, include the exported symbols in the library as the comment by @user2543253 suggested.

NB: It's a bit odd that your loadLibrary call works at all; PATH has nothing to do with it, but presuambly then your library so happens to be located in a place that is listed on your librarypath, which is the system property (of the VM, not of your OS) named 'java.library.path'; you set it with e.g.:

java -Djava.library.path=/path1:/path2 -cp /path/to/dep1.jar:/path/to/dep2.jar com.foo.Main

because of this confusion it is also possible that some different native lib file also named FTDIInterface is being loaded instead of the one you think is being loaded. If you want to be certain of what is being loaded, run System.load("/absolute/path/to/the/dll-jnilib-or-so-libraryfile.so"); - then you know for sure.

huangapple
  • 本文由 发表于 2020年8月12日 20:09:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63376241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定