From e58c2eb6300281bee444df4f742e107be8463b0f Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Tue, 6 Dec 2022 18:45:53 -0600 Subject: [PATCH] CMake: Ensure we use "-pthread" instead of "-lpthread" for thread support --- cmake/configure/configure_00_threads.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmake/configure/configure_00_threads.cmake b/cmake/configure/configure_00_threads.cmake index 33ae7145c6..8ade074556 100644 --- a/cmake/configure/configure_00_threads.cmake +++ b/cmake/configure/configure_00_threads.cmake @@ -20,6 +20,15 @@ # Clear the test flags because FindThreads.cmake will use a C compiler: CLEAR_CMAKE_REQUIRED() +# +# Ensure that we use "-pthread" instead of "-lpthread". We require +# "-pthread" for certain versions of gcc (and standard library thread +# support). Otherwise the order of libraries might be wrong on the final +# link interface and we end up with linker errors such as the following: +# /usr/bin/ld: [...]/step-69.cc.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' +# /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libpthread.so: error adding symbols: DSO missing from command line +# +SET(THREADS_PREFER_PTHREAD_FLAG true) SWITCH_LIBRARY_PREFERENCE() FIND_PACKAGE(Threads) @@ -29,6 +38,14 @@ RESET_CMAKE_REQUIRED() ADD_FLAGS(DEAL_II_LINKER_FLAGS "${CMAKE_THREAD_LIBS_INIT}") +# +# Make sure that we compile with "-pthread" as well. The "-pthread" +# compiler flag might add certain preprocessor definitions when compiling. +# +IF("${CMAKE_THREAD_LIBS_INIT}" MATCHES "-pthread") + ADD_FLAGS(DEAL_II_CXX_FLAGS "${CMAKE_THREAD_LIBS_INIT}") +ENDIF() + IF(NOT Threads_FOUND) MESSAGE(FATAL_ERROR "\nFatal configuration error: CMake was unable to detect any threading " -- 2.39.5