cmake和tesseract,如何使用cmake进行链接

问题描述 投票:1回答:3

我正在尝试构建我的应用程序对抗tesseract,我已经通过brew安装(在mac os x上工作)。

虽然我可以使用g ++和pkg-config编译我的应用程序而没有问题,但我不知道如何使用cmake做同样的事情。

我试过FIND_PACKAGE tesseract REQUIRED,但它似乎无法找到它。有没有人有样品CMakeLists.txt?

感谢帮助。

c++ opencv tesseract
3个回答
1
投票

看来在你的CMake项目中使用tesseract的唯一(或最简单)方法是下载tesseract源代码(来自here)使用以下步骤构建:

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

将“Tesseract_DIR”环境变量指定给刚刚为tesseract创建的目录。

然后在项目的CMakeLists.txt文件中,您应该具有以下行:

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.

所有这些都只是用cmake构建你的项目。


0
投票

我使用了以下findpkgconfig命令,它适用于使用brew包的MacOS。

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} )

0
投票

由于您是链接库而不是已安装的软件包,因此您可以像将任何其他库链接到cmake一样添加它

target_link_libraries( your_project tesseract )

这相当于将-ltesseract添加到g ++命令行

© www.soinside.com 2019 - 2024. All rights reserved.