Reputation: 117
Is there a way to build and use Tesseract library and corresponding Leptonica library (because Tesseract depends on Leptonica) as it can be done in Windows?
I compiled these libraries according to their instructions, but it seems that libtesseract.so.3.0.2
includes a fixed path to Leptonica shared library:
$ ldd libtesseract.so.3.0.2
linux-vdso.so.1 => (0x00007fffbc5ff000)
**liblept.so.4 => /usr/local/lib/liblept.so.4 (0x00007fa8400fd000)**
libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x00007fa83fcae000)
libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x00007fa83fa5e000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa83f5e4000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fa83f2de000)
libm.so.6 => /lib64/libm.so.6 (0x00007fa83f059000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa83ecc5000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fa83eaaf000)
/lib64/ld-linux-x86-64.so.2 (0x0000003080200000)
It results in the OSError while running an application on a workstation where Leptonica is not installed:
OSError: liblept.so.4: cannot open shared object file: No such file or directory
Typical use case is as follows (the tesseract and leptonica libraries are in the same folder):
import ctypes
import os
import sys
lang = 'eng'
os.putenv('TESSDATA_PREFIX', ".")
tessdata = os.environ.get('TESSDATA_PREFIX')
tess_libpath = "."
tess_libname = "libtesseract.so.3.0.2"
# tess_libname = "libtesseract302.dll" works in Windows, no need to add a leponica library file
os.environ["PATH"] += os.pathsep + tess_libpath
tesseract = None
try:
tesseract = ctypes.cdll.LoadLibrary(os.path.join(tess_libpath, tess_libname))
except OSError, err:
raise
class _TessBaseAPI(ctypes.Structure): pass
TessBaseAPI = ctypes.POINTER(_TessBaseAPI)
tesseract.TessBaseAPICreate.restype = TessBaseAPI
tesseract.TessBaseAPIDelete.restype = None
tesseract.TessBaseAPIDelete.argtypes = [TessBaseAPI]
tesseract.TessBaseAPIInit3.argtypes = [TessBaseAPI,
ctypes.c_char_p,
ctypes.c_char_p]
tesseract.TessBaseAPISetImage.restype = None
tesseract.TessBaseAPISetImage.argtypes = [TessBaseAPI,
ctypes.c_void_p,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int]
tesseract.TessBaseAPIGetUTF8Text.restype = ctypes.c_char_p
tesseract.TessBaseAPIGetUTF8Text.argtypes = [TessBaseAPI]
I tried to add options --disable-shared --enable-static
when configuring Tesseract, but it didn't work out.
In my case target OS is CentOS 6.5, but I would appreciate any general answer as well.
Upvotes: 4
Views: 2014
Reputation: 328536
ldd
can't tell you whether there is an absolute path in a library. Instead, it uses the standard shared library search path and prints what it finds.
To check whether the loading would work from a different folder as well, try this:
> mkdir tmp
> cd tmp
> cp /usr/local/lib/liblept.so.4
> LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH ldd libtesseract.so.3.0.2
It should now show liblept.so.4
from the tmp
folder.
Upvotes: 1