gpt4 book ai didi

C++ 链接错误(Boost 线程)

转载 作者:行者123 更新时间:2023-11-28 06:20:35 25 4
gpt4 key购买 nike


我遇到了 boost 线程库的问题。当我将这个库添加到我的项目时,它在编译时开始失败。我试图添加到 CXX_FLAGS -lboost_system-lboost_thread

CMakeLists.txt:

cmake_minimum_required (VERSION 2.8)

set(PROJECT Refregiration_Telemetry-Device)

PROJECT(${PROJECT} CXX)

SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")

set(SRC_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/)
set(EXECUTABLE_OUTPUT_PATH ${SRC_ROOT_DIR}/bin)

set(SRC_DIR ${SRC_ROOT_DIR}/src)
set(INCLUDE_DIR ${SRC_ROOT_DIR}/include)
set(LIB_DIR ${SRC_ROOT_DIR}/lib)

INCLUDE_DIRECTORIES(${SRC_DIR} ${LIB_DIR} ${INCLUDE_DIR})

set(SOURCES main.cpp scheduler.cpp)
set(INCLUDES scheduler.hpp)

set(SOURCES_LIST)

foreach (class ${INCLUDES})
LIST (APPEND SOURCES_LIST ${INCLUDE_DIR}/${class})
endforeach ()

foreach (class ${SOURCES})
LIST (APPEND SOURCES_LIST ${SRC_DIR}/${class})
endforeach ()

#Boost include start
find_package (Boost COMPONENTS date_time thread)
include_directories (${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIR})
#set (ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${Boost_LIBRARIES})
#Boost include end

add_executable (${PROJECT} ${SOURCES_LIST})

target_link_libraries (${PROJECT} ${Boost_LIBRARIES})
#target_link_libraries (${PROJECT} ${ADDITIONAL_LIBS})

制作日志:

[ 50%] Building CXX object CMakeFiles/Refregiration_Telemetry-Device.dir/src/main.cpp.o
[100%] Building CXX object CMakeFiles/Refregiration_Telemetry-Device.dir/src/scheduler.cpp.o
Linking CXX executable ../bin/Refregiration_Telemetry-Device
/usr/bin/ld: CMakeFiles/Refregiration_Telemetry-Device.dir/src/main.cpp.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [../bin/Refregiration_Telemetry-Device] Error 1
make[1]: *** [CMakeFiles/Refregiration_Telemetry-Device.dir/all] Error 2
make: *** [all] Error 2

最佳答案

libboost_system.so 是 libboost_filesystem.so 的主要要求,因此请确保将 -lboostsystem 添加到您的命令构建或添加 find_package(Boost 1.60.0 COMPONENTS filesystem system REQUIRED) 到 CMakeLists 文件。

PS: 例如我使用了Boost 1.60.0,你可以使用任何版本来构建。此命令也适用于 linux,要在 Windows 中构建,您需要使用 visual studio 开发人员命令提示符构建 boost。

关于C++ 链接错误(Boost 线程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29369094/

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