简体   繁体   English

UnsatisfiedLinkError - 无法加载库 - 在资源路径中找不到本机库

[英]UnsatisfiedLinkError - Unable to load library - Native library not found in resource path

I have the following error at runtime, while trying to run Tess4J:在尝试运行 Tess4J 时,我在运行时遇到以下错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302': Native library (win32-x86-64/libtesseract302.dll) not found in resource path ([myproject/target/classes/, ...some jars...])

My questions are:我的问题是:

1) What exactly it tries to find and where? 1)它究竟试图寻找什么以及在哪里?

2) Why is it apparently searches for myproject/target/classes/ directory? 2)为什么它显然是在搜索myproject/target/classes/目录? I set it nowhere.我没有设置它。

3) Why is it ignores "native directory path" I set for tess4j.jar in user library descripto in Eclipse? 3)为什么它会忽略我在 Eclipse 的用户库描述中为tess4j.jar设置的“本机目录路径”? My DLLs are there.我的 DLL 在那里。 If it didn't ignore the path, it would find DLLs.如果它没有忽略路径,它会找到 DLL。

4) Why is it apparently prepending DLL name with win32-x86-64/ ? 4) 为什么它显然在 DLL 名称前面加上win32-x86-64/ I set this nowhere.我没有设置这个。 Is this standard prefix of some API?这是某些API的标准前缀吗?

5) What is "resource path"? 5)什么是“资源路径”? How to set it?如何设置?

Like the error says, it's looking for win32-x86-64/libtesseract302.dll in java.class.path .就像错误所说的那样,它正在java.class.path寻找win32-x86-64/libtesseract302.dll Part of your classpath apparently includes myproject/target/classes .您的类路径的一部分显然包括myproject/target/classes

The prefix represents the platform and architecture of the shared library to be loaded, which allows shared libraries for different targets to be included in the same archive.前缀代表要加载的共享库的平台和架构,它允许不同目标的共享库包含在同一个存档中。 If JNA cannot find the requested library name in the system load path, then it attempts to find it within your resource path (extracting it, if necessary).如果 JNA 在系统加载路径中找不到所请求的库名称,那么它会尝试在您的资源路径中找到它(如有必要,提取它)。 So if you put the DLL in a jar file, you'll need to give it the win32-x86-64 prefix in order for it to load.因此,如果将 DLL 放在 jar 文件中,则需要为其提供win32-x86-64前缀以便加载。

The "resource path" is nominally your class path; “资源路径”名义上是您的类路径; basically anywhere reachable by ClassLoader.getResource() .基本上可以通过ClassLoader.getResource()到达的任何地方。

The error stems from your trying to load 32-bit DLLs in 64-bit JVM.该错误源于您尝试在 64 位 JVM 中加载 32 位 DLL。 The possible solution is switch to 32-bit JVM;可能的解决方案是切换到 32 位 JVM; alternatively, use 64-bit Tesseract and Leptonica DLLs .或者,使用64 位 Tesseract 和 Leptonica DLL

Had the same issue, sorted with the following lines有同样的问题,按以下几行排序

System.load("/usr/local/lib/liblept.so.5")
System.loadLibrary("tesseract")

For your case, it might be different libraries but in the end is pretty much the same: just load the libraries that you need manually.对于您的情况,它可能是不同的库,但最终几乎相同:只需手动加载您需要的库。

Why don't you use JNA API http://www.java2s.com/Code/Jar/j/Downloadjna351jar.htm to load native library?为什么不使用 JNA API http://www.java2s.com/Code/Jar/j/Downloadjna351jar.htm来加载原生库? Once you putted into your project classpath, you add this code放入项目类路径后,添加此代码

NativeLibrary.addSearchPath("libtesseract302", "your native lib path"); make sure you have this libtesseract302.dll file, normally it is located at windows32 folder.请确保您有这个libtesseract302.dll文件,通常它位于windows32文件夹。

For example, if your libtesseract302.dll file in somewhere c:/abcv/aaa/libtesseract302.dll then you just set the path like this NativeLibrary.addSearchPath("libtesseract302", "c:/abcv/aaa");例如,如果您的 libtesseract302.dll 文件位于c:/abcv/aaa/libtesseract302.dll那么您只需设置这样的路径NativeLibrary.addSearchPath("libtesseract302", "c:/abcv/aaa");

I don't know how windows path look like either c:/abcv/aaa or c:\\\\abcv\\\\aaa\\\\我不知道 Windows 路径看起来像c:/abcv/aaac:\\\\abcv\\\\aaa\\\\

if you want easier way, just put all your necessary dll file into your windows32 folder, JVM will take care of it.如果您想要更简单的方法,只需将所有必需的 dll 文件放入 windows32 文件夹,JVM 会处理它。

Another issue might be you were not installing the application correctly or the application version is unmatch with your jar version.另一个问题可能是您没有正确安装应用程序或应用程序版本与您的 jar 版本不匹配。 try to install the latest application and download the latest jar to try again.尝试安装最新的应用程序并下载最新的jar 再试一次。 Hope it helps :)希望能帮助到你 :)

I had the same problem and found that this "resource path" is not set by "native directory path" .我遇到了同样的问题,发现这个“资源路径”不是由“本机目录路径”设置的。
You can however add new folders to it by using "Add External Class Folder" in the Library tab, even if this folder does not contain any class file but native library files(like DLL on Windows)但是,您可以通过使用“库”选项卡中的“添加外部类文件夹”向其中添加新文件夹,即使此文件夹不包含任何类文件但包含本机库文件(如 Windows 上的 DLL)

A few days ago I ran into the same error message when trying to load a C++ DLL with JNA.几天前,我在尝试使用 JNA 加载 C++ DLL 时遇到了相同的错误消息。 It turned out that the cause was a missing DLL that my DLL depended on.结果证明,原因是我的 DLL 所依赖的 DLL 丢失。

In my case it was the MS Visual Studio 2012 redistributable, which I then downloaded and installed on the machine and the problem was gone.就我而言,它是 MS Visual Studio 2012 可再发行组件,然后我将其下载并安装在机器上,问题就消失了。 Try using Dependency Walker to find any missing libraries and install them.尝试使用Dependency Walker查找任何缺失的库并安装它们。

我遇到了类似的问题,我尝试了上面的所有答案,但它没有解决我的问题,最后我检查了我从哪里得到了dll的源,发现我没有安装windows redistributable 2012,dll是使用它,一旦我安装它,异常就消失了。

I think an easier way to get around this error would be to revert to an earlier version where you were not getting this error.我认为解决此错误的更简单方法是恢复到没有收到此错误的早期版本。 Right click on the project folder and navigate to local history to revert to an earlier version.右键单击项目文件夹并导航到本地历史记录以恢复到早期版本。 I verified this workaround on the android studio installed on Mac OS Big sur.我在 Mac OS Big sur 上安装的 android studio 上验证了这个解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在Mac OS X上加载JNA库时出现“无法加载库:在资源路径中找不到JNA本机支持” - “Unable to load library: JNA native support not found in resource path” on trying to load JNA library on Mac OS X 在资源路径中找不到本机库 - native library not found in resource path UnsatisfiedLinkError:无法加载库 - UnsatisfiedLinkError: Unable to load library UnsatisfiedLinkError:在资源路径 (.) 中找不到本机库 (com/sun/jna/android-x86-64/libjnidispatch.so) - UnsatisfiedLinkError: Native library (com/sun/jna/android-x86-64/libjnidispatch.so) not found in resource path (.) 找不到android项目中的本机库(UnsatisfiedLinkError) - Native library in android project not found (UnsatisfiedLinkError) UnsatisfiedLinkError:找不到本地库“ wcepeer”(Mysaifu) - UnsatisfiedLinkError : Native library 'wcepeer' not found (Mysaifu) Windows,JNA:无法加载本机库-UnsatisfiedLinkError - Windows, JNA: Cannot load native library - UnsatisfiedLinkError java.lang.UnsatisfiedLinkError:无法加载库 - java.lang.UnsatisfiedLinkError: Unable to load library UnsatisfiedLinkError,但是库在路径中 - UnsatisfiedLinkError, but library is in path java.lang.UnsatisfiedLinkError:无法加载库“ TSCLIB”:找不到指定的模块 - java.lang.UnsatisfiedLinkError: Unable to load library 'TSCLIB': The specified module could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM