Can't get CMake to link pthreads to my lib

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't get CMake to link pthreads to my lib

Jean-Michaël Celerier
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

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Can't get CMake to link pthreads to my lib

Rolf Eike Beer
Am 2017-08-08 15:45, schrieb Jean-Michaël Celerier:

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

set(CMAKE_THREAD_PREFER_PTHREAD On)

> find_package(Threads REQUIRED)

Greetings,

Eike
--
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Can't get CMake to link pthreads to my lib

Jean-Michaël Celerier
I've tried this and also
set(THREADS_PREFER_PTHREAD_FLAG TRUE)

but this didn't work either.



-------
Jean-Michaël Celerier

On Tue, Aug 8, 2017 at 4:01 PM, Rolf Eike Beer <[hidden email]> wrote:
Am 2017-08-08 15:45, schrieb Jean-Michaël Celerier:
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)

set(CMAKE_THREAD_PREFER_PTHREAD On)

find_package(Threads REQUIRED)

Greetings,

Eike
--
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake