问题
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.
回答1:
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.
回答2:
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} )
回答3:
Since you are linking against the library and not an installed package, you can just add it like you would link any other library into cmake
target_link_libraries( your_project tesseract )
this is the equivalent of adding -ltesseract to your g++ command line
回答4:
Can't comment on Long's answer due to lack of rep, but using
target_link_libraries( FOOBAR ${TESSERACT_LINK_LIBRARIES})
target_link_libraries( FOOBAR ${LEPTONICA_LINK_LIBRARIES})
worked for me, after using the same findpkgconfig method. Using:
target_link_libraries( FOOBAR ${TESSERACT_LIBRARIES})
gave me a linker error when compiling
来源:https://stackoverflow.com/questions/38128260/cmake-and-tesseract-how-to-link-using-cmake