10

I've had tesseract and Tess4J running on my MBP for a while now. Today I started to migrate my app to the server and started installing everything on the server. Prior to running Tess4J in tomcat I tried to run a simple java program to make sure everything is fine and dandy. It's not...

  • I'm on a centOS 64bit server
  • I've installed tesseract and its working fine - tesseract myimage.jpg mytext produces data

However, running my simple class that useses Tess4j produces this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'tesseract': libtesseract.so: cannot open shared object file: No such file or directory

What I've done so far

  • I've ran sudo ldconfig after installing tesseract
  • I've search for libtesseract.so and its found in /usr/local/lib/libtesseract.so

Folder on server contains these files:

myimge.png  
ghost4j-0.3.1.jar  
jai_imageio.jar  
jna.jar  
maslab.jar  
pngj.jar  
tess4j.jar  
TesseractExample.class  
TesseractExample.java

tesseract -v produces:

tesseract -v
tesseract 3.02.02
 leptonica-1.69
  libjpeg 6b : libpng 1.2.49 : libtiff 3.9.4 : zlib 1.2.3

Question

How can I make Tess4J aware that libtesseract.so does exist?enter code here

Omnipresent
  • 29,434
  • 47
  • 142
  • 186
  • how did you install tesseract? I followed the [link you gave below](https://code.google.com/p/tesseract-ocr/downloads/list) and downloaded one with english data, but that doesn't seem to *install* tesseract, it seems like just data for english recognition. – Don Cheadle Oct 26 '14 at 21:23
  • Try http://stackoverflow.com/a/29726897/4499919 – udit043 Sep 15 '16 at 21:21

4 Answers4

28

I had this problem too.

Did you run the following after installing tesseract:

sudo ldconfig

That fixed it for me.

Løiten
  • 3,185
  • 4
  • 24
  • 36
youdsmedia
  • 334
  • 6
  • 15
  • Good answer :-) – udit043 Sep 15 '16 at 21:21
  • ldconfig tells applications where they can find the linked libraries. That's why the above command can be needed after installing something new, e.g.: http://manpages.ubuntu.com/manpages/bionic/man8/ldconfig.8.html – Tuula Oct 18 '19 at 08:33
8

You must set LD_LIBRARY_PATH environment variable to the path where libtesseract.so is.

export LD_LIBRARY_PATH=/usr/local/lib
Marcos Pirmez
  • 256
  • 4
  • 5
5

It is necessary to define the variable jna.platform.library.path. For instance:

-Djna.platform.library.path=/usr/local/lib/

Ren
  • 1,111
  • 5
  • 15
  • 24
2

Maybe it is a 32 bit library .so installed.

Zombo
  • 1
  • 62
  • 391
  • 407
Jean Waghetti
  • 4,711
  • 1
  • 18
  • 28
  • I installed tesseract-ocr-3.02.eng.tar.gz from here http://code.google.com/p/tesseract-ocr/downloads/list and compiled it. if it installed a 32 bit library...is there a work around it? – Omnipresent Mar 09 '13 at 04:41
  • Try setting the path to the library like one of these: http://www.chilkatsoft.com/java-loadLibrary-Linux.asp – Jean Waghetti Mar 09 '13 at 04:47
  • hmm well that got rid of the `libtesseract.so` error but now I've got same error for these two `/usr/local/lib/libtesseract.so.3.0.2: liblept.so.3: cannot open shared object file:` and these aren't doing away by explicitply adding the path in code or adding them in the paths already in `java.library.path` – Omnipresent Mar 09 '13 at 04:57
  • Do you have liblet.so or liblept.so.3? Make a symlink if one of these is not present. – Jean Waghetti Mar 09 '13 at 05:00
  • hmm no. I don't have either one of those. What do I make a symblink link from ...since I don't have these two files present.. – Omnipresent Mar 09 '13 at 05:09
  • The symlink was in case only one of them was not present. Maybe you'll need to install liblept. – Jean Waghetti Mar 09 '13 at 05:14
  • I reinstalled leptonica and this time around ran `sudo ldconfig` so it created `liblept.so.3` and placed it in `/usr/local`. I'm able to execute the class now just fine. Now into having it work on tomcat! Thanks for help – Omnipresent Mar 09 '13 at 05:32