Use Tesseract as a library at Windows with Qt

172 views
Skip to first unread message

Hüseyin Kozan

unread,
Sep 18, 2017, 2:42:10 AM9/18/17
to tesseract-ocr

Hello,

I am sory if this is a duplicate question. Searched, but couldn't find a proper solution.

I want to use Tesseract 3.05.01 as a library with Qt.

Tried to donwload and install UB-Mannheim, but no includes directory.

Tried to install with cppan like "cppan --build pvt.cppan.demo.google.tesseract.libtesseract" but there was no include directory.

Tried to build and install from source like "git clone ... && cppan && mkdir win64 && cd win64 && cmake .. ..." and cannot link Tesseract project with Leptonica project from cloned source. Searched a flag to set leptonica path, but no luck.


Is it possible to build from source and produce `"includes/", "*.lib" files, and "*.dll" files both Tesseract and Leptonica projects ?

My environment : VS2017 x64, CMake 3.91, CPPAN 0.2.3, Qt 5.9.1 MSVC2017 64bit, Qt Creator 4.4.0


John Grossman

unread,
Jan 4, 2018, 1:34:36 AM1/4/18
to tesseract-ocr

Hey there.  I wanted to do pretty much the same thing as you and after an hour or so of messing around I managed to get something which looks like it will work for me, so I thought I would post and let you know what I ended up doing (since there do not seem to be any responses yet).

FWIW - I was building for x86, not x64.  I started with the standard build-from-git instructions, but made sure to check out the 3.05 branch before building (I just moved my local master branch to the 3.05 branch)
  1. git clone ...
  2. git reset --hard origin/3.05
  3. cppan
  4. mkdir build && cd build
  5. cmake ..
Once this completed, I had a build directory with a tesseract.sln file in it as well as a libtesseract.vcxproj file.  Loading the solution file in VS2017 allowed me to build both release and debug versions of libtesseract without any issues.  In the end, however, instead of just directly linking in the library to my own project, I ended up just adding the existing libtesseract.vcxproj file to my own project's solution.

After that, all I needed to do was...
  1. Add a reference from my project to the libtesseract project in my solution.
  2. Add the include paths to C/C++ -> General -> Additional Include Directories.  I needed to add "api", "ccmain", "ccstruct", and "ccutil" (all in the directory you checked-out tesseract into).
  3. My project is a DLL and (for some reason) had Linker -> Link Library Dependencies set to "yes".  I needed to turn this off to avoid a situation where two different copies of MSVCRT were getting linked (you probably will not have to do this).
Be sure to change all of the versions (release and debug) of your project's config when adding the include dirs.  Now I just need to make sure that everything is actually working, but at least I am building and linking without problems now :D

hope this helps.

-john

John Grossman

unread,
Jan 4, 2018, 4:31:53 PM1/4/18
to tesseract-ocr
ugh, following up with some corrections on what I hacked together in case they help anyone...

Previously, I had said...

"""
My project is a DLL and (for some reason) had Linker -> Link Library Dependencies set to "yes".  I needed to turn this off to avoid a situation where two different copies of MSVCRT were getting linked (you probably will not have to do this).
"""

This is not correct.  This option just tells the build system to link the import library for dependencies (in my case, set by adding the libtesseract project as a dependency of the library I am building).  Turning this off didn't fix my problem, it just hid it.  As soon as I tried to actually use the library, I failed to link because none of the tesseract symbols were available.

Turning this back on then caused the multiple symbol collision problem I was having earlier.  I tracked this down to the following cause...

cppan generated a cmake file which used the cmake __create_def feature to automatically create a dll export file for the project.  The vcxproj file was set to use this generated exports def file.  The trouble is that the automatically generated file was WAY to inclusive; it was exporting pretty much all of the symbols from std:: in addition to everything else.  So, when it came time to link, all of the symbols from the standard library I was using in my library were colliding with the symbols from the libtesseract import library which had been generated.

The thing is, generating an explicit export definition file is not needed at all.  The tesseract library is already well set up to flag what should and should not be exported using the TESS_API macro (defined in ccutil\platform.h).  So, all I needed to do is remove the explicit export definition file and everything worked out just fine (Configuration Properties -> Linker -> All Options -> Module Definition File should be empty).

-john

Reply all
Reply to author
Forward
0 new messages