3

I'm trying to use the Java JNA wrapper for Tesseract OCR API but I keep getting java.lang.UnsatisfiedLinkError exception

I downloaded the latest version from http://sourceforge.net/projects/tess4j/

I made sure that I use a 32 bit JVM. Following is the exception trace.

Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found.

at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:79)
at net.sourceforge.tess4j.TessAPI.(TessAPI.java:40)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:205)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:189)
at net.sourceforge.tess4j.Main.main(Main.java:12)

Any obvious mistakes that I'm doing?

I used the sample code from http://tess4j.sourceforge.net/codesample.html

package net.sourceforge.tess4j.example;

import java.io.File;
import net.sourceforge.tess4j.*;

public class TesseractExample {

    public static void main(String[] args) {
        File imageFile = new File("eurotext.tif");
        Tesseract instance = Tesseract.getInstance();  // JNA Interface Mapping
        // Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping

        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }}

I added a VM argument such as jna.library.path=${pathtodll2} and get the below error if I use the argument,

Error: Could not find or load main class jna.library.path=D:\OCR\Tess4J\lib\win32-x86

I'm using the latest version from the Test4J project, Version 2.0 (29 March 2015)

  • Upgrade to Tesseract 3.03 (r1050), which is compatible with Tesseract 3.03RC on Linux
  • Refactor Tesseract class for extensibility and thread-safety
  • Update English language data for Tesseract 3.02

I'm running it on Windows 7, 32 bit machine. Java 7.

When I try using the process Explorer I'm not able to see the dlls getting loaded but I'm not sure since the exception is thrown right away.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
aswath86
  • 551
  • 5
  • 14
  • can you post your Code? – Prashant Apr 06 '15 at 13:29
  • Make sure that your shared library and all its dependent libraries are in the same directory and that that directory is on `jna.library.path`. – technomage Apr 06 '15 at 13:57
  • What Tess4J & Tesseract versions and OS? – nguyenq Apr 06 '15 at 23:51
  • have added all the information that you guys have asked. Its definitely that the dlls are not getting referred right? But I'm not sure how to fix this. – aswath86 Apr 07 '15 at 06:28
  • I even tried placing the dlls in the System32 folder and still no luck. But my error message doesn't say anything about any particular dll but it says "The specified module could not be found.". Wondering what is happening. – aswath86 Apr 07 '15 at 07:31
  • Tess4J autoextracts the DLLs to `C:\Users\xxx\AppData\Local\Temp\tess4j` and loads them from there. You won't need to set `jna.library.path` variable, unless you want to load your custom DLLs instead. – nguyenq Apr 09 '15 at 01:43
  • Hey nguyenq, thanks for the reply. I guess you were the author of that project right? Anyways, I did find out about C:\Users\xxx\AppData\Local\Temp\tess4j temp path and made sure that the dlls are copied their but it still throws me a "The specified module could not be found." It however doesn't say if its the dll that it could not find. It just says ""The specified module could not be found."" – aswath86 Apr 10 '15 at 10:44
  • I also used process explorer to find if the dlls are getting loaded but no luck. I even copied the dlls to the system32 folder and did a reboot and then ran the program, all to see "The specified module could not be found." one more time. I dont know what it is looking for. – aswath86 Apr 10 '15 at 10:47
  • The Tesseract DLL has a dependency on Visual C++ Redistributable. Have you installed that? – nguyenq Apr 10 '15 at 13:13
  • Please see here https://stackoverflow.com/a/61177017/5717031 – Mike ASP Apr 12 '20 at 19:34

3 Answers3

6

I resolved this problem by updating to Visual C++ Redistributable Packages for Visual Studio 2013

Visual C++ Redistributable for VS2012 is not enough.

This tool: http://www.dependencywalker.com/ helped me a lot to found the problem.

Olivier Masseau
  • 778
  • 7
  • 23
1

Visual C++ Redistributable Packages for Visual Studio 2013 is the package you need to install on your computer :).

And it will work 4 sure....

Tanuj Verma
  • 388
  • 2
  • 7
0

Solution to UnsatisfiedLinkError :

  1. install Visual C++ 2015 Redistributable Packages.

  2. try to move tess4j folder from your local to system where Exception occurred.