From 8ee4966ea54520730bc382dbb85e4e7c03cb531a Mon Sep 17 00:00:00 2001 From: r-value Date: Wed, 24 Nov 2021 12:34:23 +0800 Subject: [PATCH] Prefer `-pthread` flag for pthread According to gcc doc, `-pthread` flag will link the program against libraries like libatomic on demand. Using `-lpthread` in CFLAGS and LDFLAGS causes absense of these libraries, thus failing to build on architectures which needs soft atomic operation implementation. --- cmake/LinkHelpers.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/LinkHelpers.cmake b/cmake/LinkHelpers.cmake index 5b33d503..f4264aad 100644 --- a/cmake/LinkHelpers.cmake +++ b/cmake/LinkHelpers.cmake @@ -27,6 +27,7 @@ macro(target_link_static_threads TARGET) # use a statically link winpthread target_link_libraries("${TARGET}" PRIVATE "-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive,-Bdynamic") else() + set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) target_link_libraries("${TARGET}" PRIVATE ${CMAKE_THREAD_LIBS_INIT}) endif()