Java mac OS X 上的 Tess4j 不满意链接错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21394537/
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
Tess4j unsatisfied link error on mac OS X
提问by nestrocuation
Hey i am trying to use tess4j for tesseract and having this issue for eclipse on mac osx .
嘿,我正在尝试将 tess4j 用于 tesseract,并且在 mac osx 上遇到了 eclipse 的这个问题。
My tesseract is working fine from terminal but trying to run tess4j through tesseract throws me an error .
我的 tesseract 从终端工作正常,但尝试通过 tesseract 运行 tess4j 会引发错误。
java.lang.UnsatisfiedLinkError: Unable to load library 'tesseract': Native library (darwin/libtesseract.dylib)
java.lang.UnsatisfiedLinkError:无法加载库“tesseract”:本机库(darwin/libtesseract.dylib)
i do have tessetact dylib and its named libtesseract.dylib in my opt/local/lib which i installed using macport .
我的 opt/local/lib 中确实有 tessetact dylib 及其命名的 libtesseract.dylib,我使用 macport 安装了它。
Thanks for your help
谢谢你的帮助
回答by nguyenq
回答by maresa
I know it's an old post. I had this problem too recently when I tried to use Tess4J
. However, I managed to find a way around it. I've written a post about it http://www.microshell.com/programming/java/performing-optical-character-recognition-in-java/
我知道这是一个旧帖子。我最近在尝试使用Tess4J
. 但是,我设法找到了解决方法。我写了一篇关于它的帖子http://www.microshell.com/programming/java/performing-optical-character-recognition-in-java/
In short, the problem is because tess4j-2.0.0.jar
doesn't include MacOS library. So I just modified the maven cached jar on mine by doing these steps:
简而言之,问题是因为tess4j-2.0.0.jar
不包含 MacOS 库。所以我只是通过执行以下步骤修改了我的 maven 缓存 jar:
cd /Users/user/.m2/repository/net/sourceforge/tess4j/tess4j/2.0.0
(adjust the directory where your tess4j JAR file resides)mkdir darwin
jar uf tess4j-2.0.0.jar darwin
cp /opt/local/lib/libtesseract.3.dylib darwin/libtesseract.dylib
jar uf tess4j-2.0.0.jar darwin/libtesseract.dylib
jar tf tess4j-2.0.0.jar
(to verify that the file is included)
cd /Users/user/.m2/repository/net/sourceforge/tess4j/tess4j/2.0.0
(调整 tess4j JAR 文件所在的目录)mkdir darwin
jar uf tess4j-2.0.0.jar darwin
cp /opt/local/lib/libtesseract.3.dylib darwin/libtesseract.dylib
jar uf tess4j-2.0.0.jar darwin/libtesseract.dylib
jar tf tess4j-2.0.0.jar
(验证文件是否包含在内)
I was then able to run my Java program after I modify the tess4j-2.0.0.jar
file. Below is my MacOS version.
然后我就可以在修改tess4j-2.0.0.jar
文件后运行我的 Java 程序。下面是我的 MacOS 版本。
user@laptop:~$ uname -a
Darwin Maresas-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
回答by Andrew Neilson
This is exactly what I was after today, so thanks for the Q&A above. As one additional step beyond what maresa mentioned, I ran into this error after fixing the one you asked about:
这正是我今天所追求的,所以感谢上面的问答。作为 maresa 提到的额外步骤,我在修复了您所询问的错误后遇到了这个错误:
java.lang.UnsatisfiedLinkError: dlopen(/var/folders/sq/rh89_ntd7jqdlv9__25zj9dr0000gp/T/jna--913086793/jna8800789057827590119.tmp, 9): Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /usr/local/lib/liblept.4.dylib
Reason: image not found
So to fix this I needed to set up a symlink for libjpeg.8.dylib:
所以为了解决这个问题,我需要为 libjpeg.8.dylib 设置一个符号链接:
ln -s /usr/local/Cellar/jpeg/8d/lib/libjpeg.8.dylib /usr/local/lib/libjpeg.8.dylib
Not sure if there is a way to do this without the symlink (i.e. package it in the jar), but I hope this helps anyone else who is looking at this post.
不确定是否有办法在没有符号链接的情况下执行此操作(即将其打包在 jar 中),但我希望这可以帮助正在查看这篇文章的其他人。
回答by Michael Miklavcic
I had a very similar issue with Ghost4j, i.e.
我有一个与 Ghost4j 非常相似的问题,即
InvocationTargetException: Unable to load library 'gs': Native library (darwin/libgs.dylib) not found in resource path
Instead of modifying jar files, point jna to the appropriate lib path by setting jna.library.path
. In Eclipse, you need to set the system property in run configurations - SO answer for this here - https://stackoverflow.com/a/862405/2163229
不要修改 jar 文件,而是通过设置将 jna 指向适当的 lib 路径jna.library.path
。在 Eclipse 中,您需要在运行配置中设置系统属性 - 所以在这里回答 - https://stackoverflow.com/a/862405/2163229
If you're using Maven exec:
如果您使用的是 Maven exec:
mvn -Djna.library.path=/opt/local/lib/ exec:java -Dexec.mainClass="foo.bar.NativeThingy"
or
或者
export MAVEN_OPTS="-Djna.library.path=/opt/local/lib/" && mvn exec:java -Dexec.mainClass="foo.bar.NativeThingy"
Obviously, set the path to wherever your libs are installed. In my case, I ran $ locate libgs.dylib
and found the above path.
显然,将路径设置为安装库的位置。就我而言,我运行$ locate libgs.dylib
并找到了上述路径。
References:https://jna.java.net/javadoc/com/sun/jna/NativeLibrary.html
参考资料:https : //jna.java.net/javadoc/com/sun/jna/NativeLibrary.html
回答by Long Nguyen
You need install the tesseract lib on your Mac.
您需要在 Mac 上安装 tesseract 库。
brew install tesseract --with-all-languages
brew install tesseract --with-all-languages