链接Boost线程库 [英] Linking Boost thread library

查看:121
本文介绍了链接Boost线程库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的C ++项目中包含Boost的线程库。我的CMake文件是这样的:

I am trying to include Boost's thread library in my C++ project. My CMake file is like so:

cmake_minimum_required(VERSION 3.6)
project(LearningC)

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp Student.cpp Student.h)

add_executable(LearningC ${SOURCE_FILES})

target_link_libraries(LearningC ${Boost_LIBRARIES})

我收到一个错误:

Undefined symbols for architecture x86_64:
  "boost::this_thread::interruption_point()", referenced from:
      boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in main.cpp.o
   [More stack traces...]

我在做什么错了?

推荐答案

我找到了解决方案。基本上,Boost的大部分代码都位于C ++头文件(.hpp)中。但是某些库需要编译和链接...下面的代码有效!

I found a solution. Basically, Boost has most of its code in C++ headers (.hpp). Some of the libraries however need to be compiled and linked... The code below works!

cmake_minimum_required(VERSION 3.6)
project(LearningC)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp Student.cpp Student.h)

add_executable(LearningC ${SOURCE_FILES})

find_package(Boost COMPONENTS thread system REQUIRED)

include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(LearningC ${Boost_LIBRARIES})

这篇关于链接Boost线程库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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