Skip to content

Compiling Tesseract and Leptonica

Charles Weld edited this page Nov 10, 2018 · 1 revision

Sometimes custom versions of tesseract library might be needed. To produce the valid libtesseract and leptonica dll's, each library must be built with statically linked dependencies and then placed in x64/x86 directory from where the C# wrapper will load it.

Note: AVX optimizations are currently disabled for the builds supplied with this wrapper as they are known to cause DllNotFoundException on some configurations. Using custom build might increase perfomance on modern CPU's.

Libtesseract

See the Compiling#windows tesseract page for the full description of the building process and this issue which describes static linking.

Clone master branch of tesseract repo and edit cppan.yml file:

local_settings:
    short_local_names: true <-- optional, uncomment to produce dll without long prefixes in filename
    generator: Visual Studio 15 2017 Win64 <-- Uncomment and set your generator
    use_shared_libs: false
projects:
    libtesseract:
        shared_only: true

Run (you need to have cppan.exe be in your $PATH):

cppan --build .

cppan will create link to the Visual Studio solution and build it. Alternatively, cppan --generate . can be used to only generate solution. Then, build can be started manually from the Visual Studio (building only libtesseract project is enough).

Note: cppan generated Win32 project for me despite Visual Studio 15 2017 Win64 generator. Neither setting current_build: vs2017_64 nor setting generator under build section worked, so I had to change

builds:
    vs2017:
        generator: Visual Studio 15 2017 Win64

libtesseract.dll will be in the bin directory of the generated solution.

Leptonica

git clone https://github.com/DanBloomberg/leptonica.git
cd leptonica
cppan
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" -DCPPAN_BUILD_SHARED_LIBS=0 ..
cmake --build . --config Release

The produced leptonica dll will reside in the bin directory of the generated solution.

Credits

Thanks to ArXen42 and tdhintz (See Issue 436)

Clone this wiki locally