将Boost与cmake和clang链接-对符号的未定义引用 [英] Linking Boost with cmake and clang - undefined reference to symbol

查看:113
本文介绍了将Boost与cmake和clang链接-对符号的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C ++程序中,我包括boost的filesystemregex头文件以及最终的线程支持.我希望cmakeclang在构建期间针对它们进行链接.

In my C++ program, I am including boost's filesystem and regex headers and eventually thread support. I would like cmake and clang to link against them during build time.

我收到以下错误:

[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文件中包含了必要的链接和标志,但是我必须缺少链接的顺序或标志.因此,我掉了很多根头发.

I believe I have included the necessary links and flags in my CmakeList file, but I must be missing the order or a flag for linking. I have lost many hairs because of this.

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})

推荐答案

boost_system库丢失

boost_system library is missing

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

尝试:

find_package(Boost 1.56 COMPONENTS system filesystem regex REQUIRED)

即使您不将其包含在程序中,文件系统或regex lib仍可能会将其用作依赖项

Even if you don't include it in your program, filesystem or regex lib might still use it as dependency

这篇关于将Boost与cmake和clang链接-对符号的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆