我有以下 cmake 配置。
conan_cmake_configure(REQUIRES
catch2/2.13.7
fmt/6.1.2
termcolor/2.0.0
date/3.0.1
asio/1.20.0
tl-expected/20190710
GENERATORS cmake_find_package)
...
...
...
find_package(fmt REQUIRED)
include_directories(${fmt_INCLUDE_DIR})
link_libraries(${fmt_LIBRARIES})
find_package(termcolor REQUIRED)
include_directories(${termcolor_INCLUDE_DIR})
link_libraries(${termcolor_LIBRARIES})
find_package(date REQUIRED)
include_directories(${date_INCLUDE_DIR})
link_libraries(${date_LIBRARIES})
find_package(asio REQUIRED)
include_directories(${asio_INCLUDE_DIR})
link_libraries(${asio_LIBRARIES})
find_package(tl-expected REQUIRED)
include_directories(${tl-expected_INCLUDE_DIR})
link_libraries(${tl-expected_LIBRARIES})
我可以像這樣#include 庫:
#include <asio.hpp>
#include <fmt/format.h>
但我沒有找到任何關于如何準確地#include expectedlib 的資訊。我已經嘗試過 https://github.com/hannahwhy/conan-tl-expected/blob/stable/1.0.1/test_package/example.cpp 中expected.hpp的示例
它是 fatal error C1083: No such file or directory
uj5u.com熱心網友回復:
我沒有使用 conan_cmake_configure 包裝器,但使用目標是推薦的現代 CMake 方法。您正在使用的 conan cmake 包裝器中的自述檔案有一些應該有用的片段。
基本上,cmake_find_package 生成器將從包中定義 CMake 目標,并在每個目標上定義屬性,例如包含目錄、庫、編譯定義等。每當您使用 target_link_libraries(TargetA TargetB) 時,所有傳遞依賴項都將由 CMake 處理,而無需擔心指定包含目錄等(您也應該為自己的專案使用目標)。
因此,與 fmt 的鏈接非常簡單(取自 cmake 包裝器存盤庫上的示例):
find_package(fmt)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
如果您想確定包宣告的目標,您可以檢查由 conan 創建的 CMake 組態檔。
編輯:剛剛意識到這本身并不能回答您的問題,但這可以更容易地理解出了什么問題。在您當前的 CMake 代碼中, ${x_LIBRARIES} 可能只是空的,您沒有直接意識到它。對于目標,如果您嘗試使用錯誤的包名稱進行鏈接,CMake 將拋出錯誤。
uj5u.com熱心網友回復:
謝謝你的提示。答案實際上很簡單(通常如此)。
cmake在創建 include_directories 和 link_libaries 變數時轉換-為_。所以這修復了它:
find_package(tl-expected REQUIRED)
include_directories(${tl_expected_INCLUDE_DIR})
link_libraries(${tl_expected_LIBRARIES})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/339981.html
上一篇:在C 中查找字符陣列的大小
下一篇:UDP客戶端池發送但不接收
