undefined reference to boost::system::system_category()

undefined reference to boost::system::system_category()

https://stackoverflow.com/questions/9723793/undefined-reference-to-boostsystemsystem-category-when-compiling/50146757#50146757
https://stackoverflow.com/questions/36367533/change-the-order-of-compiler-flags
https://stackoverflow.com/questions/13467072/c-boost-undefined-reference-to-boostsystemgeneric-category

方法1

find_package(Boost 1.60.0 COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")
    link_directories(${Boost_LIBRARY_DIRS})
    include_directories(${Boost_INCLUDE_DIRS})
endif()
if(Boost_FOUND)
    target_link_libraries(BoostTest ${Boost_LIBRARIES})
endif()

方法2

add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)

补充
当系统找不到本地符合要求的boost版本时,取消

set(Boost_NO_BOOST_CMAKE ON)

设置自定义的boost路径

set(BOOST_ROOT "/usr")

链接库文件
语法:

target_link_libraries( [item1 [item2 [...]]] [[debug|optimized|general] ] ...)
target_link_libraries(myProject comm) # 连接libhello.so库,默认优先链接动态库
target_link_libraries(myProject libcomm.a) # 显示指定链接静态库
target_link_libraries(myProject libcomm.so) # 显示指定链接动态库
target_link_libraries(myProject -lcomm)

————————————————
版权声明:本文为CSDN博主「大笼包不够吃」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_34160181/article/details/111964982

你可能感兴趣的:(boost)