【问题标题】:How to include a library which I installed with Homebrew如何包含我用 Homebrew 安装的库
【发布时间】:2021-12-18 05:14:31
【问题描述】:

我已经用自制软件安装了 boost 库,如果我写的话:

include_directories(/opt/homebrew/Cellar)
link_directories(/opt/homebrew/Cellar/boost/1.76.0/)
add_executable(Project main.cpp)
target_link_libraries(Project boost)

然后将其包含在我的脚本中:

#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

没有找到,我写的时候:

#include <boost/1.76.0/include/boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

它确实找到了,但我收到以下错误:

/opt/homebrew/Cellar/boost/1.76.0/include/boost/multiprecision/cpp_int.hpp:12:10: fatal error: 'boost/multiprecision/number.hpp' file not found
#include <boost/multiprecision/number.hpp>
The number.hpp file can't include the boost library.

任何人都可以理解这一点并可以帮助我吗?

【问题讨论】:

  • 最好使用find_package(Boost REQUIRED COMPONENTS multiprecision) ... target_link_libraries(Project PRIVATE Boost::multiprecision)(不是 100% 确定该组件是否是子模块以及如何在 cmake 中将 boost 作为仅标头库包含在内。您可能需要通过 @987654326 指定安装目录@ 或 CMAKE_PREFIX_PATH.

标签: c++ boost cmake libraries


【解决方案1】:

要添加一个Boost header-only库,例如multiprecision和cmake,通常你需要做的就是:

find_package(Boost)
link_libraries(Boost::headers)

如果 Boost 没有正确安装,您仍然可以添加:

include_directories(/opt/homebrew/include)

或:

include_directories(/opt/homebrew/Celler/boost/1.76.0/include)

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-06
    • 2016-05-07
    相关资源
    最近更新 更多