Yuliia Ashomok
Yuliia Ashomok

Reputation: 8598

Tess4j Issue in Windows: java.lang.UnsatisfiedLinkError: The specified module could not be found in instance.doOCR(imageFile)

After 2 days of googling I am still unable to find the solution of my issue with Tess4j version 3.0: java.lang.UnsatisfiedLinkError: The specified module could not be found.

I write server side Spring boot app on my Windows 10 x64. I used this tutorial http://tess4j.sourceforge.net/tutorial/ I make ant test in tess4j project's source and this command works ok in my PC. I also have Visual C++ Redistributable for VS2012 and Visual C++ Redistributable for VS2013 installed. But I have missed dlls in my PC, libtesseract304.dll depends on:

Can it be the reason of problem? But how it is possible, that Tess4J-3.0-src project works ok in my PC?

My full stack trace:

java.lang.UnsatisfiedLinkError: The specified module could not be found.

    at com.sun.jna.Native.open(Native Method) ~[jna.jar:4.2.1 (b0)]
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:263) ~[jna.jar:4.2.1 (b0)]
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403) ~[jna.jar:4.2.1 (b0)]
    at com.sun.jna.Library$Handler.<init>(Library.java:147) ~[jna.jar:4.2.1 (b0)]
    at com.sun.jna.Native.loadLibrary(Native.java:502) ~[jna.jar:4.2.1 (b0)]
    at com.sun.jna.Native.loadLibrary(Native.java:481) ~[jna.jar:4.2.1 (b0)]
    at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(Unknown Source) ~[tess4j-3.0.jar:na]
    at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source) ~[tess4j-3.0.jar:na]
    at net.sourceforge.tess4j.Tesseract.init(Unknown Source) ~[tess4j-3.0.jar:na]
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
    at ocr.OCRController.handleFileUpload(OCRController.java:109) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]

My code:

ITesseract instance = new Tesseract(); // JNA Interface Mapping

instance.setDatapath(new File(datapath).getPath()); 
instance.setLanguage("eng");      
try {
    String result = instance.doOCR(imageFile); //error here
} catch (TesseractException e) {
    System.err.println(e.getMessage());
}

maven:

<dependency>
    <groupId>jai_imageio</groupId>
    <artifactId>com.jai_imageio</artifactId>
    <version>3.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/jai_imageio.jar</systemPath>
</dependency>
<dependency>
    <groupId>commons-io-2.4</groupId>
    <artifactId>com.commons-io-2.4</artifactId>
    <version>3.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/commons-io-2.4.jar</systemPath>
</dependency>
<dependency>
    <groupId>jna</groupId>
    <artifactId>com.jna</artifactId>
    <version>3.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/jna.jar</systemPath>
</dependency>
<dependency>
    <groupId>tess4j-3.0</groupId>
    <artifactId>com.tess4j-3.0</artifactId>
    <version>3.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/tess4j-3.0.jar</systemPath>
</dependency>

I also tried to load libs in force way:

Runtime.getRuntime().loadLibrary("lib/win32-x86-64/gsdll64");
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/libtesseract304");

But without success:

There was an unexpected error (type=Internal Server Error, status=500).
C:\Users\Iuliia\IdeaProjects\ENumbersBackend\lib\win32-x86-64\libtesseract304.dll: Can't find dependent libraries

Thank you for any help!

Upvotes: 2

Views: 6569

Answers (2)

Yuliia Ashomok
Yuliia Ashomok

Reputation: 8598

The problem is not connected with Windows 10.

I've already fix the error with adding

<dependency>
    <groupId>net.sourceforge.tess4j</groupId>
    <artifactId>tess4j</artifactId>
    <version>3.0.0</version>
</dependency>

instead all previous maven dependencies.

Upvotes: 1

Marged
Marged

Reputation: 10973

I think you our misled by the output of depends.exe.

The DLL only imports these other dlls:

dumpbin libtesseract304.dll /imports|find ".dll"
Dump of file libtesseract304.dll
    WS2_32.dll
    liblept171.dll
    MSVCP120.dll
    MSVCR120.dll
    KERNEL32.dll

To doublecheck you can get the linker version used to compile that dll:

dumpbin libtesseract304.dll /headers | find "linker version"
           12.00 linker version

So all you need is the Visual Studio 2013 Runtime (again: don't be misled: 12.0 is 2013, which can be rather confusing)

Presumably the liblept171.dll is the thing that is missing, so you should check where it is stored and why the one project is able to find it and not the other. A good idea is to copy all dependencies into a common path and setting java.library.path to that directory (just for testing purposes)

liblept171.dll is part of lept4j, there is a accordingly named .jar in your lib directory which contains that dll:

7z l lib\lept4j-1.0.1.jar | find ".dll"
2015-11-14 11:46:04 .....      2406400      2406400  win32-x86-64\liblept171.dll
2015-11-14 11:46:04 .....      1834496      1834496  win32-x86\liblept171.dll

In addition you should take care that the bitness of your JRE, the Visual Studio Runtime and Tesseract do match. If in doubt: install x86 and x64.

As a further troubleshooting aid you might want to find out where the dll is being searched for. Use procmon.exe with a filter for that dll.

Upvotes: 3

Related Questions