将Boost与cmake和clang链接 - 未定义的符号引用

时间:2014-09-14 19:31:25

标签: c++ boost cmake clang

在我的C ++程序中,我包含了boost filesystemregex标题,并最终支持了线程。我希望cmakeclang在构建期间与它们链接。

我收到以下错误:

[100%] Building CXX object CMakeFiles/a.out.dir/src/main.cpp.o
Linking CXX executable a.out
/usr/bin/ld: CMakeFiles/a.out.dir/src/main.cpp.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/libboost_system.so.1.56.0: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)

相信我在CmakeList文件中包含了必要的链接和标志,但我必须错过订单或链接标记。因此,我失去了许多头发。

的CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(TARGET_NAME "a.out")

project(${TARGET_NAME} C CXX)
file(GLOB ALL_SRC_FILES "src/*.cpp")

add_definitions("-std=c++11 -Wall -g -pthread")
find_package(Boost 1.56 COMPONENTS filesystem regex REQUIRED)
message(status ": Boost Include: ${Boost_INCLUDE_DIR}")
message(status ": Boost Libraries Dir: ${Boost_LIBRARY_DIRS}")
message(status ": Boost Libraries: ${Boost_LIBRARIES}")

include_directories(${Boost_INCLUDE_DIR})
include_directories(/usr/include/c++/4.9.1)
include_directories(/usr/lib/clang/3.5.0/include)
include_directories(src)
list(APPEND CMAKE_CXX_FLAGS "-pthread")
add_executable(${TARGET_NAME} ${ALL_SRC_FILES})
link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries(${TARGET_NAME} ${Boost_LIBRARIES})

1 个答案:

答案 0 :(得分:4)

缺少boost_system库

/usr/lib/libboost_system.so.1.56.0: error adding symbols

尝试:

find_package(Boost 1.56 COMPONENTS system filesystem regex REQUIRED)

即使您没有将它包含在您的程序中,文件系统或正则表达式lib仍可能将其用作依赖项