【问题标题】:CMake cannot find Boost libraries filestem, thread, date_time, iostreams, systemCMake 找不到 Boost 库 filestem、thread、date_time、iostreams、system
【发布时间】:2019-07-12 10:00:03
【问题描述】:

我正在尝试从源代码构建 PCL,但 CMake 无法找到某些库。但是,当我检查图书馆时。我知道这已经被问了很多,但我刚刚开始使用 CMake 我已经在互联网上搜索了好几天,但找不到有效的解决方案。我觉得我错过了任何帮助将不胜感激

所以我按照其他人的建议在我的 CMakeLists.txt 中写了这个

cmake_minimum_required(VERSION 3.13)
set(Boost_ADDITIONAL_VERSIONS "1.67.0")
set(BOOST_ROOT "C:/local/boost_1_67_0/boost")

set(BOOST_INCLUDEDIR "C:/local/boost_1_67_0/")
set(BOOST_LIBRARYDIR "C:/local/boost_1_67_0/lib64-msvc-14.0")

set (Boost_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.67.0)

但我仍然不断收到同样的错误:

     CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.67.0

  Boost include path: C:/local/boost_1_67_0

  Could not find the following static Boost libraries:

          boost_filesystem
          boost_thread
          boost_date_time
          boost_iostreams
          boost_system

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
  to the location of Boost.
Call Stack (most recent call first):
  cmake/pcl_find_boost.cmake:36 (find_package)
  CMakeLists.txt:428 (include)

老实说,我会接受任何关于我现在可以尝试的事情的建议。如果我可以提供任何其他我没有想到的有用信息,请随时发表评论或留言。 谢谢

【问题讨论】:

    标签: c++ boost build cmake


    【解决方案1】:

    就像 timko.mate 建议的那样,find_package 使用组件是正确的做法。

    但是,您应该考虑使用基于目标的 API:

    target_link_libraries(your_exe PUBLIC Boost::system Boost::filesystem)
    

    另外,为了让 CMake 找到 Boost,你应该调整你的前缀路径。这通常在您的项目中调用 cmake 时完成:

    cmake -DMAKE_PREFIX_PATH=c:/local/ ..
    

    这样,您的 cmake 文件中不应包含硬编码路径。

    【讨论】:

    • 愚蠢的问题,但在这种情况下,“your_exe”会是什么 .exe?我想我不完全理解您使用目标 API 的意思。就像你建议的 include_directories 给出了问题。再次感谢您的快速回复
    • @p0ps1c1e 当您调用add_executable(a_exe ...)add_library(a_lib ...) 时,a_liba_exe 都是目标。然后,您可以将目标链接到 boost 的目标以获得包含目录。调用include_directory(...) 被认为是不好的做法。你应该使用target_link_libraries(...)target_include_directories(...)
    • @p0ps1c1e 我的错,我在答案中使用了错误的命令。
    【解决方案2】:

    几个月前我也遇到过同样的问题。这解决了我的问题。

    find_package(Boost 1.67.0 COMPONENTS system filesystem REQUIRED)
    include_directories(${Boost_INCLUDE_DIRS})
    

    【讨论】:

    • 当使用 find_package 我强烈推荐使用基于目标的 API 而不是目录
    猜你喜欢
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-02
    • 2019-12-29
    • 2020-11-29
    • 2017-07-19
    相关资源
    最近更新 更多