0
votes

I'm desperately trying to compile Tesseract-ocr (4.0) on a Windows Machine with some restrictions.

  • We are doing multi-platforms : an automated compilation must be possible (command-line)
  • We are using specific 3rd party libraries : the compilation must accept custom path / libraries for most of its dependencies
  • We are already using most of the 3rd party libraries for other part of the code : the compilation must not recompile them (thus, no cppan)
  • Leptonica has been built with our special 3rdparty (ZLib, LibPng ..)
  • Our project must "include" tesseract alongside theses specific 3rdparty

Problem :

I have strong issue specifying custom paths for Tesseract. Under Unix (CentOS, Ubuntu 16/18, Debian 8/9 ..), I was able to achieve my goal with the tools autogen autoconf autoheaders pkg-config.

Under Windows, autoconf-archive and pkg-config are unavailable (from what I tried) ; rendering autoconf unusable. I was neither able to compile using CMake and specifying a custom path for Leptonica (even after writing a new pkgconfig for leptonica).

Things I tried :

  • Using MinGW and autoconf
  • Manually installing pkg-config
  • Cheating with autoconf-archive .m4 into aclocal
  • Creating a VisualStudio project with cppan and modify it
  • Various ways of telling CMake to search elsewhere for 3rdparty

Things that work on Linux :

  • Autoconf with modified PKGConfig for custom compiled Leptonica (--with-extra-libraries PKG_CONFIG_PATH CPPFLAGS LDFLAGS)

Things I have not tried :

  • Installing Leptonica on the machine (Not the point here)
  • Rewriting CMakeFiles
  • Unknown solutions ?

Possible Solutions

  • MinGW (Windows) with pkg-config autoconf-archive
  • Unknown way to tell CMake Leptonica custom path
  • VisualStudio project without cppan
  • Yours ?

Thank your for your interest.

EDIT 1

By trying various ways of manually installing pkg-config, Autoconf seemed to be unaware of its presence. This error was about pkg-config missing package (How to install pkg config in windows?).

CPPAN was deeply part of the visual studio project and I couldn't see how I could separate them.

I usually tell configure to look for leptonica package with the arguments --with-extra-libraries and PKG_CONFIG_PATH. CMake however, uses the "macro" find_package(Leptonica $PATH CONFIG REQUIRED). By looking at it a little bit, I was (maybe) able to specify its path with CMAKE_PREFIX_PATH, CMAKE_MODULE_PATH, Leptonica_DIR. The compilation was still unsuccessfull due to missing config files (LeptonicaConfig.cmake or leptonica-config.cmake).

I pointed theses variables to various folders of the leptonica folder after building it. For information, I built Leptonica with its configure as such :

bash configure --enable-shared=false --without-giflib --without-libwebp --without-libopenjpeg LDFLAGS="-LPATH/TO/ZLIB -LPATH/TO/LIBPNG .." CPPFLAGS="-IPATH/TO/ZLIB/INCLUDE ..."

I, however, was unable to locate theses files (while seeing a LeptonicaConfig.cmake.in under LeptonicaDir/cmake/template)

I hope I answered your questions. Please tell me if you need further details.

1
Welcome to Stack Overflow! While you describe your problematic area in many details, your question seems to be "too broad": you ask us about possible ways, but, I guess, any of suggested ways could work. You have failed to make any of them to work... but you don't describe details of the problems. E.g., "Things I tried: ... Various ways of telling CMake to search elsewhere for 3rdparty". What exactly have you tried? What exact problem (e.g. an error message) have you got?Tsyvarev
KDE Craft is a system that prepares compilation environment and has recipes (called blueprints) to build a lot of packages. It might have sense to build on top of that. At least you will have no problem locating 3rd party packages and they can already be present in Craft's blueprints tree.arrowd
@Tsyvarev Alright. I tried to edit my initial question for a detailed response. ThanksArnaud Loyer
@arrowd I looked into it and I don't think it meets my prerequisite "We are already using most of the 3rd party libraries for other part of the code : the compilation must not recompile them". Thank you for your suggestion.Arnaud Loyer

1 Answers

1
votes

To compile tesseract-4.0.0 on Windows with MSYS and MinGW:

Prerequisites:

Open Start Menu > MSYS2 64bit > MSYS2 MSYS and run the following commands:

$ pacman -Syu
#### Close terminal window and open it again (MSYS2 MSYS) ###
$ pacman -Su
$ pacman -S base-devel
$ pacman -S mingw-w64-i686-toolchain
$ pacman -S mingw-w64-x86_64-toolchain
$ pacman -S mingw-w64-i686-cmake
$ pacman -S mingw-w64-x86_64-cmake

32-bit Compilation:

Open Start Menu > MSYS2 64bit > MSYS2 MinGW 32-bit and run the following commands:

$ cd /home/tesseract/tesseract-4.0.0
$ pacman -S mingw-w64-i686-leptonica
$ ./autogen.sh
$ ./configure --prefix=/home/tesseract/install/windows-i686
$ make -j4
$ make install

64-bit Compilation:

Open Start Menu > MSYS2 64bit > MSYS2 MinGW 64-bit and run the following commands:

$ cd /home/tesseract/tesseract-4.0.0
$ pacman -S mingw-w64-x86_64-leptonica
$ ./autogen.sh
$ ./configure --prefix=/home/tesseract/install/windows-x86_64
$ make -j4
$ make install

The compiled tesseract will be installed on: C:/msys64/home/tesseract/install