我通过这个添加了增强:

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/

10-11 22:07
查看更多