繁体   English   中英

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

[英]cmake and tesseract, how to link using cmake

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

虽然我可以使用 g++ 和 pkg-config 毫无问题地编译我的应用程序,但我不确定如何使用 cmake 做同样的事情。

我试过 FIND_PACKAGE tesseract REQUIRED 但它似乎无法找到它。 有人有示例 CMakeLists.txt 吗?

感谢帮助。

在带有 CMake 的项目中使用 tesseract 的唯一(或最简单的)方法似乎是下载 tesseract 源代码(从这里)使用以下步骤构建:

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 构建您的项目。

我使用了以下 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} )

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

target_link_libraries( your_project tesseract )

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

由于缺乏代表,无法对 Long 的回答发表评论,但使用

target_link_libraries( FOOBAR ${TESSERACT_LINK_LIBRARIES})

target_link_libraries( FOOBAR ${LEPTONICA_LINK_LIBRARIES})

在使用相同的 findpkgconfig 方法后,为我工作。 使用:

target_link_libraries( FOOBAR ${TESSERACT_LIBRARIES})

编译时给了我一个链接器错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM