gpt4 book ai didi

c++ - CMake:对 boost 库的 undefined reference

转载 作者:搜寻专家 更新时间:2023-10-31 00:29:47 24 4
gpt4 key购买 nike

我通过这个添加了 boost :

set(Boost_USE_STATIC_LIBS        ON) 
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})

project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP ${Boost_LIBRARIES})

当我编译源代码时,我得到:

demo.cpp:(.text+0x3d3): undefined reference to `boost::system::generic_category()'

我检查了拼写(Boost_LIBRARIES 与 BOOST_LIBRARIES)但没问题。

我使用包 boost-devel 在 Fedora 中安装了 boost。

最佳答案

source code 中查找,Boost_LIBRARIES根据传给find_package的组件列表进行填充。尝试:

find_package(Boost REQUIRED COMPONENTS system)

您还应该使用导入的目标:

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS system)

# the call to include_directories is now useless:
# the Boost::system imported target used below
# embeds the include directories

project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP Boost::system)

关于c++ - CMake:对 boost 库的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39513269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com