链接加强与cmake并铛 - 未定义的参考符号(Linking Boost with cmake a

2019-10-20 22:56发布

在我的C ++程序,我包括升压转换器的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})

Answer 1:

boost_system库丢失

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

尝试:

find_package(Boost 1.56 COMPONENTS system filesystem regex REQUIRED)

即使你不包括在你的程序,文件系统或正则表达式的lib可能仍然把它作为依赖



文章来源: Linking Boost with cmake and clang - undefined reference to symbol