Could not find a package configuration file provided by "Leptonica"

1.3k Views Asked by At

I am trying to generate a visual studio 2019 C++ project from the tesseract 4.1.1 source code. Ultimately, I want to include a tesseract C++ project in my custom solution that consumes OCR results.

When I follow these steps:

  1. Download and extract tesseract code https://github.com/tesseract-ocr/tesseract/archive/refs/tags/4.1.1.zip to "C:\tesseract" directory.
  2. Execute the following commands in a Developer Command Prompt for VS 2019:

C:\Windows\System32>cd "C:\tesseract"
C:\tesseract>mkdir build
C:\tesseract>cd build
C:\tesseract\build>cmake ..

I receive this error:

Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
CMake Error at CMakeLists.txt:224 (find_package):
  Could not find a package configuration file provided by "Leptonica"
  (requested version 1.74) with any of the following names:

  LeptonicaConfig.cmake
  leptonica-config.cmake

  Add the installation prefix of "Leptonica" to CMAKE_PREFIX_PATH or set
  "Leptonica_DIR" to a directory containing one of the above files.  If
  "Leptonica" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "C:/tesseract/build/CMakeFiles/CMakeOutput.log".

Here is the relative portion of the CMakeLists.txt file:

CMakeLists.txt screenshot

find_package(PkgConfig)
if(PKG_CONFIG_EXECUTABLE AND NOT Leptonica_DIR)
    pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
    link_directories(${Leptonica_LIBRARY_DIRS})
else()
    find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
endif()
if (NOT Leptonica_FOUND)
    message(FATAL_ERROR "Cannot find required library Leptonica. Quitting!")
endif(NOT Leptonica_FOUND)

find_package(LibArchive)
if(LibArchive_FOUND)
    set(HAVE_LIBARCHIVE ON)
endif()

Solution:

After studying the tutorials provided by user898678, and experimentation, here's what I've learned.

The commands listed in the tutorials (and in the list provided below) can be executed in a normal command prompt. They need not be executed in the Developer Command prompt for Visual Studio.

Tutorials (in general) make it very confusing, because they attempt to include steps for everything, and every scenario. In my case, I'm simply looking for a working VS project for Tesseract. This blogpost provided by user898678 was the most useful. I distilled the commands I needed to run to the following:

set INSTALL_DIR="C:\Temp\Tesseract"
set PATH=%PATH%;%INSTALL_DIR%\bin
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat" x64
set INCLUDE=%INCLUDE%;%INSTALL_DIR%\include
set LIBPATH=%LIBPATH%;%INSTALL_DIR%\lib

git clone --depth 1 https://github.com/DanBloomberg/leptonica.git
cd leptonica
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release ^
   -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% ^
   -DBUILD_PROG=OFF -DSW_BUILD=OFF -DBUILD_SHARED_LIBS=ON
cmake --build build  --config Release --target install
cd ..

git clone -b 4.1.1 --depth 1 https://github.com/tesseract-ocr/tesseract.git
cd tesseract
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% ^
    -DCMAKE_PREFIX_PATH=%INSTALL_DIR% ^
    -DLeptonica_DIR=%INSTALL_DIR%\lib\cmake  ^
    -DBUILD_TRAINING_TOOLS=OFF -DSW_BUILD=OFF ^
    -DOPENMP_BUILD=OFF -DBUILD_SHARED_LIBS=ON
cmake --build build --config Release --target install

For me, after culling all the discussion and instructions scattered among the command syntax, the commands became much easier to understand.

1

There are 1 best solutions below

0
On BEST ANSWER

There are several tutorial how to build tesseract on windows with cmake and VS e.g. https://bucket401.blogspot.com/2021/03/building-tesserocr-on-ms-windows-64bit.html (you can ignore end of tutorial - python module), minimalist tesseract or with clang