【问题标题】:Linking Boost with cmake and clang - undefined reference to symbol将 Boost 与 cmake 和 clang 链接 - 对符号的未定义引用
【发布时间】:2014-09-14 19:31:25
【问题描述】:

在我的 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})

【问题讨论】:

标签: c++ boost cmake clang


【解决方案1】:

boost_system 库丢失

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

试试:

find_package(Boost 1.56 COMPONENTS system filesystem regex REQUIRED)

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

【讨论】:

  • 做到了!我应该知道的更好。非常感谢你看到这个:-)
猜你喜欢
  • 1970-01-01
  • 2020-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-12
相关资源
最近更新 更多