[CMake] Can't get CMake to link pthreads to my lib

Jean-Michaël Celerier jeanmichael.celerier at gmail.com
Tue Aug 8 09:45:41 EDT 2017


Here's my CMakeLists.txt :

>>>>>>>

cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(oscour)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_CXX_FLAGS "-fconcepts -fsanitize=address -fsanitize=undefined")
set(CMAKE_EXE_LINKER_FLAGS "-fconcepts -fsanitize=address
-fsanitize=undefined")

add_subdirectory(uWebSockets)

find_package(Threads REQUIRED)

add_library(oscour INTERFACE)
target_sources(oscour INTERFACE
  ${CMAKE_CURRENT_SOURCE_DIR}/oscour/oscour.hpp)

target_include_directories(oscour INTERFACE oscour/)
target_link_libraries(oscour INTERFACE uWS Threads::Threads)
target_compile_options(oscour INTERFACE -std=c++17)

add_executable(udp examples/udp.cpp)
target_link_libraries(udp PRIVATE oscour)

add_executable(tcp examples/tcp.cpp)
target_link_libraries(tcp PRIVATE oscour)

<<<<<<<<

As you can see, I call
find_package(Threads REQUIRED)
but at no point my example executables, named udp and tcp, link to -pthread
(or -lpthread) (which of course makes my build fails).
I also tried to link them explicitely to Threads::Threads. This did not
work either.

e.g. when doing make in verbose mode, the link invocation is :

 /usr/bin/g++ -fconcepts -fsanitize=address -fsanitize=undefined -std=c++17
-fconcepts -fsanitize=address -fsanitize=undefined
CMakeFiles/complete.dir/examples/udp.cpp.o  -o udp  uWebSockets/libuWS.a
/usr/lib/libssl.so /usr/lib/libcrypto.so /usr/lib/libz.so

there is no hint of pthreads in there... what can I do ?

Best

Jean-Michaël Celerier
http://www.jcelerier.name
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170808/03c4b33b/attachment.html>


More information about the CMake mailing list