我通过这个添加了 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/