Skip to content

Compiling – GitInstallation

Stefan Weil edited this page Mar 26, 2019 · 55 revisions

Installing Tesseract from Git

These are the instructions for installing Tesseract from the git repository. You should be ready to face unexpected problems.

Installing With Autoconf Tools

In order to do this; you must have automake, libtool, leptonica, make and pkg-config installed. In addition, you need Git and a C++ compiler.

On Debian or Ubuntu, you can probably install all required packages like this:

apt-get install automake g++ git libtool libleptonica-dev make pkg-config

The optional manpages are built with asciidoc:

apt-get install --no-install-recommends asciidoc

If you want to build the Tesseract training tools as well, you'll also require Pango:

apt-get install libpango1.0-dev

Afterwards, to clone the master branch to your computer, do this:

git clone https://github.com/tesseract-ocr/tesseract.git

or to make a shallow clone with commit history truncated to the latest commit only:

git clone --depth 1  https://github.com/tesseract-ocr/tesseract.git

or to clone a different branch/version:

git clone https://github.com/tesseract-ocr/tesseract.git --branch <branchName> --single-branch

Note: Tesseract requires Leptonica v1.74 or newer. If your system has only older versions of Leptonica, you must compile it manually from source available at DanBloomberg/leptonica.

Finally, run these:

    cd tesseract
    ./autogen.sh
    ./configure
    make
    sudo make install
    sudo ldconfig

If you get this error:

make  all-recursive
Making all in ccstruct
/bin/sh ../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -
I..  -I../ccutil -I../cutil -I../image -I../viewer -I/opt/local/
include -I/usr/local/include/leptonica  -g -O2 -MT blobbox.lo -MD -MP -
MF .deps/blobbox.Tpo -c -o blobbox.lo blobbox.cpp
mv -f .deps/blobbox.Tpo .deps/blobbox.Plo
mv: rename .deps/blobbox.Tpo to .deps/blobbox.Plo: No such file or
directory
make[3]: *** [blobbox.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Try to run autoreconf -i after running ./autogen.sh.

Unit test builds

Such builds can be used to run the automated regression tests, which have additional requirements. This includes the additional dependencies for the training tools (as mentioned above), and downloading all git submodules, as well as the model repositories (*.traineddata):

# Clone the Tesseract source tree:
git clone https://github.com/tesseract-ocr/tesseract.git
# Clone repositories with model files (from the same directory):
git clone https://github.com/tesseract-ocr/tessdata.git
git clone https://github.com/tesseract-ocr/tessdata_best.git
git clone https://github.com/tesseract-ocr/tessdata_fast.git
git clone https://github.com/tesseract-ocr/langdata_lstm.git
# Change to the Tesseract source tree and get all submodules:
cd tesseract
git submodule update --init
# Build the training tools (see above). Here we use a release built with sanitizers:
./autogen.sh
mkdir -p bin/unittest
cd bin/unittest
../../configure --disable-shared 'CXXFLAGS=-g -O2 -Wall -Wextra -Wpedantic -fsanitize=address -fsanitize=leak -fsanitize=undefined -fstack-protector-strong -ftrapv'
make training
# Run the unit tests:
make check
cd ../..

This will create log files for all unit tests, both individual and accumulated, under bin/unittest/unittest. They can also be run standalone, for example

bin/unittest/unittest/stringrenderer_test

Failed tests will show prominently as segfaults or SIGILL handlers (depending on the platform).

Debug Builds

Such builds produce Tesseract binaries which run very slowly. They are not useful for production, but good to find or analyze software problems. This is a proven build sequence:

cd tesseract
./autogen.sh
mkdir -p bin/debug
cd bin/debug
../../configure --enable-debug --disable-shared 'CXXFLAGS=-g -O0 -Wall -Wextra -Wpedantic -fsanitize=address -fsanitize=leak -fsanitize=undefined -fstack-protector-strong -ftrapv'
# Build tesseract and training tools. Run `make` if you don't need the training tools.
make training
cd ../..

This activates debug code, does not use a shared Tesseract library (that makes it possible to run tesseract without installation), disables compiler optimizations (allows better debugging with gdb), enables lots of compiler warnings and enables several run time checks.

Profiling Builds

Such builds can be used to investigate performance problems. Tesseract will run slower than without profiling, but with acceptable speed. This is a proven build sequence:

cd tesseract
./autogen.sh
mkdir -p bin/profiling
cd bin/profiling
../../configure --disable-shared 'CXXFLAGS=-g -p -O2 -Wall -Wextra -Wpedantic'
# Build tesseract and training tools. Run `make` if you don't need the training tools.
make training
cd ../..

This does not use a shared Tesseract library (that makes it possible to run tesseract without installation), enables profiling code, enables compiler optimizations and enables lots of compiler warnings.

Optionally this can also be used with debug code by adding --enable-debug and replacing -O2 by -O0.

The profiling code creates a file named gmon.out in the current directory when Tesseract terminates. GNU gprof is used to show the profiling information from that file.

Release Builds for Mass Production

The default build creates a Tesseract executable which is fine for processing of single images. Tesseract then uses 4 CPU cores to get an OCR result as fast as possible.

For mass production with hundreds or thousands of images that default is bad because the multi threaded execution has a very large overhead. It is better to run single threaded instances of Tesseract, so that every available CPU core will process a different image.

This is a proven build sequence:

cd tesseract
./autogen.sh
mkdir -p bin/release
cd bin/release
../../configure --disable-openmp --disable-shared 'CXXFLAGS=-g -O2 -fno-math-errno -Wall -Wextra -Wpedantic'
# Build tesseract and training tools. Run `make` if you don't need the training tools.
make training
cd ../..

This disabled OpenMP (multi threading), does not use a shared Tesseract library (that makes it possible to run tesseract without installation), enables compiler optimizations, disables setting of errno for mathematical functions (faster execution!) and enables lots of compiler warnings.

Builds for fuzzing

Fuzzing is used to test the Tesseract API for bugs. Tesseract uses OSS-Fuzz, but fuzzing can also run locally. A newer Clang++ compiler is required.

Build example (fix the value of CXX for the available clang++):

cd tesseract
./autogen.sh
mkdir -p bin/fuzzer
cd bin/fuzzer
../../configure --disable-openmp --disable-shared CXX=clang++-7 CXXFLAGS='-g -O2 -Wall -Wextra -Wpedantic -D_GLIBCXX_DEBUG -fsanitize=fuzzer-no-link,address,undefined'
# Build the fuzzer executable.
make fuzzer-api
cd ../..

Example (Show help information):

bin/fuzzer/fuzzer-api -help=1

Example (Run the fuzzer with a know test case):

bin/fuzzer/fuzzer-api clusterfuzz-testcase-minimized-fuzzer-api-5670045835853824

Example (Run the fuzzer to find new bugs):

Example (Run the fuzzer with a know test case):

nice bin/fuzzer/fuzzer-api -jobs=16 -workers=16

Building using Windows Visual Studio

See Compiling for Windows.

As of 02/02/2020


These wiki pages are no longer maintained.

All pages were moved to tesseract-ocr/tessdoc.

The latest documentation is available at https://tesseract-ocr.github.io/.


Clone this wiki locally