Linking Boost thread library

前端 未结 2 1143
无人及你
无人及你 2021-01-15 11:43

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_pack         


        
2条回答
  •  萌比男神i
    2021-01-15 12:25

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

提交回复
热议问题