I want to use the newest version of Boost library and have the following contents of a CMakeLists.txt
file:
cmake_minimum_required (VERSION 3.0)
project (foo)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DBOOST_ERROR_CODE_HEADER_ONLY -lpthread")
# set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread")
add_executable (first first.cpp)
With that I keep getting the following linker error:
undefined reference to `pthread_detach
However, if I compile my code without the use of CMake, with the following command:
g++ foo.cpp -std=c++11 -DBOOST_ERROR_CODE_HEADER_ONLY -lpthread
It works fine.
The question is how to get it to work using CMake. Why doesn't it work when I specify the compiler flags via setting CMAKE_CXX_FLAGS
? I thought I might have to specify CMAKE_EXE_LINKER_FLAGS
instead, but doing that doesn't help at all.