简体   繁体   English

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

[英]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).我正在尝试针对 tesseract 构建我的应用程序,我已经通过 brew 安装了它(在 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.虽然我可以使用 g++ 和 pkg-config 毫无问题地编译我的应用程序,但我不确定如何使用 cmake 做同样的事情。

I tried FIND_PACKAGE tesseract REQUIRED but it can't seem to find it.我试过 FIND_PACKAGE tesseract REQUIRED 但它似乎无法找到它。 Does anyone have a sample CMakeLists.txt ?有人有示例 CMakeLists.txt 吗?

Appreciate the help.感谢帮助。

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

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.将“Tesseract_DIR”环境变量指定为您刚刚为 tesseract 创建的目录。

Then in the CMakeLists.txt file of your project you should have the following lines:然后在您项目的 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.

After the all just build your project with cmake.毕竟,只需使用 cmake 构建您的项目。

I used the following findpkgconfig command, it works for me on MacOS with brew packages.我使用了以下 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} )

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

target_link_libraries( your_project tesseract )

this is the equivalent of adding -ltesseract to your g++ command line这相当于将 -ltesseract 添加到您的 g++ 命令行

Can't comment on Long's answer due to lack of rep, but using由于缺乏代表,无法对 Long 的回答发表评论,但使用

target_link_libraries( FOOBAR ${TESSERACT_LINK_LIBRARIES})

target_link_libraries( FOOBAR ${LEPTONICA_LINK_LIBRARIES})

worked for me, after using the same findpkgconfig method.在使用相同的 findpkgconfig 方法后,为我工作。 Using:使用:

target_link_libraries( FOOBAR ${TESSERACT_LIBRARIES})

gave me a linker error when compiling编译时给了我一个链接器错误

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

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