Run Tesseract on linux without shared libraries

731 views
Skip to first unread message

Łukasz Antczak

unread,
Jan 20, 2016, 3:17:12 PM1/20/16
to tesseract-ocr

Hello!
I need to run tesseract without leptonica installed on the CentOS system. 
I have leptonica liblept.so available, and I am able to compile tesseract pointing to that directory.

Is it possible to run tesseract without setting up LD_LIBRARY_PATH? 
Maybe there is some way to add some parameter to let tesseract know where leptonica is located in execution phase?

Is it possible to compile tesseract to be independent from shared library liblept.so? Is there any "configure" script parameter available to compile liblept.so into tesseract executable?

Nick White

unread,
Jan 21, 2016, 8:29:58 AM1/21/16
to tesser...@googlegroups.com
Hi Łukasz,

> Is it possible to run tesseract without setting up
> LD_LIBRARY_PATH?

Why don't you want to just use LD_LIBRARY_PATH? I suspect, to be
honest, that it would be difficult to compile the leptonica library
into the tesseract executable. It would be fun and interesting (to
me) to try to produce a statically linked tesseract binary, but
probably not easy.

Seriously, I reckon you'd be much better off spending your time
dumping a leptonica install directory somewhere under /home and
setting LD_LIBRARY_PATH appropriately. I can't imagine a situation
where that wouldn't be reasonable, but maybe I am missing something?

> Maybe there is some way to add some parameter to let tesseract
> know where leptonica is located in execution phase?

Ah, rereading this part, is it just that you are executing it in a
way that setting environment variables is tricky / forbidden? My
first thought in such a case would be a one-liner shell script that
executes tesseract for you. Any reason that wouldn't work either?

Nick

Nick White

unread,
Jan 21, 2016, 2:56:43 PM1/21/16
to tesser...@googlegroups.com
So this email prompted me to try something a little crazy, but it
worked; I just built a statically linked tesseract binary :)

A long time ago I wrote some plain makefiles which didn't rely on
any automake / cmake stuff. The main devs weren't interested,
understandably, but it was useful and fun for me. This was before
the code was in git, and when lots of training stuff was in the
repository, so sharing my changes wasn't easy and I never bothered.

I decided to dig out those makefiles and update them to track the
current codebase, in part because it seemed like a nice idea, and
also because I thought it might be an easy way to see if static
linking was easy. I added a directory called 'simplemake' to the
root of the tesseract repository, which contains a Makefile and a
config.mk file (as well as several files that just list where source
files are and what to do with them). It worked well, so I pushed it
to a branch called 'simplemake-integrated'; see:
https://github.com/nickjwhite/tesseract/tree/simplemake-integrated

To enable static linking just edit 'simplemake/config.mk' to
uncomment the two lines underneath the line:
# Needed for static linking (uncomment lines to enable static linking)

Note that you'll need the dev packages of various image decoding
libraries installed, providing the .a (static) libraries. Hopefully
your distribution provides these easily. My distribution (Debian
stable) does for everything except for openjp2, which I had to build
myself to get the appropriate .a file.

This make infrastructure is something I quite like, and it is
completely self-contained; it can happily co-exist alongside the
existing build infrastructure, as cmake is doing now. Whether
anybody else is interested in it I don't know, but it is a very
simple, fast, and customisable way of building, and definitely works
correctly with -j12 or whatever I have thrown at it. Any feedback
would be very welcome indeed.

Nick
Reply all
Reply to author
Forward
0 new messages