Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Ensure we use "-pthread" instead of "-lpthread" for thread support #14540

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion cmake/configure/configure_00_threads.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,29 @@
# Clear the test flags because FindThreads.cmake will use a C compiler:
clear_cmake_required()

find_package(Threads)
#
# 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)

find_package(Threads)
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 "
Expand Down