簡體   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