Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake and tesseract, how to link using cmake

I'm trying to build my application against tesseract, which i have installed through brew (working on mac os x).

While i can compile my application without problem using g++ and pkg-config, i'm not sure how to do the same with cmake.

I tried FIND_PACKAGE tesseract REQUIRED but it can't seem to find it. Does anyone have a sample CMakeLists.txt ?

Appreciate the help.

like image 542
ATv Avatar asked Oct 30 '25 00:10

ATv


2 Answers

I used the following findpkgconfig command, it works for me on MacOS with brew packages.

find_package( PkgConfig REQUIRED)

pkg_search_module( TESSERACT REQUIRED tesseract )

pkg_search_module( LEPTONICA REQUIRED lept )

include_directories( ${TESSERACT_INCLUDE_DIRS} )

include_directories( ${LEPTONICA_INCLUDE_DIRS} )

link_directories( ${TESSERACT_LIBRARY_DIRS} )

link_directories( ${LEPTONICA_LIBRARY_DIRS} )

add_executable( FOOBAR main )

target_link_libraries( FOOBAR ${TESSERACT_LIBRARIES} )

target_link_libraries( FOOBAR ${LEPTONICA_LIBRARIES} )
like image 94
Long Avatar answered Nov 01 '25 15:11

Long


It seems the only (or the easiest) way to use tesseract in your project with CMake is to download tesseract sources (from here ) The build with the following steps:

cd <Tesseract source directory>
mkdir build
cd build
cmake ../
make
sudo make install

Specify "Tesseract_DIR" environment variable to the directory you just created for tesseract.

Then in the CMakeLists.txt file of your project you should have the following lines:

find_package( Tesseract 3.05 REQUIRED ) # 3.05 is currently the latest version of the git repository.
include_directories(${Tesseract_INCLUDE_DIRS})
target_link_libraries(<your_program_executable> ${Tesseract_LIBRARIES})  # you can link here multiple libraries as well.

After the all just build your project with cmake.

like image 28
Arsen Avatar answered Nov 01 '25 14:11

Arsen