【问题标题】:What Boost package should I search for with cmake to include code from Boost Functional?我应该使用 cmake 搜索什么 Boost 包以包含来自 Boost Functional 的代码?
【发布时间】:2013-05-09 19:42:55
【问题描述】:

在我的代码中,我想使用boost::hash<pair<int, int>>,为此我需要:

#include <boost/functional/hash.hpp>

我使用cmake 来构建我的项目。我应该在CMakeLists.txt 中使用find_package 请求什么包?现在我有:find_package(Boost COMPONENTS program_options regex REQUIRED)。我没有任何错误,但我怀疑这是因为我安装了所有的 boost 库。

【问题讨论】:

    标签: c++ boost cmake


    【解决方案1】:

    Functional 是一个只有头文件的库,所以你不需要添加任何东西,因为只有头文件的库不会被链接。另见Which boost libraries are header-only?http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html#header-only-libraries

    【讨论】:

    • 所以我只需要对需要构建的库使用find_package?如果这个标头是我从 Boost 中使用的唯一东西怎么办?我不应该配置cmake来寻找项目的需求吗? (我对cmake 的实际功能有点困惑,因为我最近从autotools 切换到它。
    • 这更像是一个问题,boost 比 cmake 能做什么,但你只需要 find_package 和构建库。仅标头库不会被链接,因此不需要添加它们:boost.org/doc/libs/1_53_0/more/getting_started/…
    猜你喜欢
    • 2019-11-29
    • 2021-07-05
    • 2022-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    相关资源
    最近更新 更多