diff --git a/scripts/templates/libapi.cpp.mako b/scripts/templates/libapi.cpp.mako index 97bc623f9a..c2fb67808e 100644 --- a/scripts/templates/libapi.cpp.mako +++ b/scripts/templates/libapi.cpp.mako @@ -82,13 +82,4 @@ try { %endfor %endfor - -namespace { -// This uselessFunc is needed to ensure that pthread is linked correctly against -// ur_loader.so for gcc-9 -void uselessFunc() { - std::thread UselessThread([]{}); -} -} - } // extern "C" diff --git a/source/loader/CMakeLists.txt b/source/loader/CMakeLists.txt index b1a3e8bb91..fe9d24d429 100644 --- a/source/loader/CMakeLists.txt +++ b/source/loader/CMakeLists.txt @@ -48,6 +48,13 @@ if (UNIX) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) target_link_libraries(ur_loader PRIVATE Threads::Threads) + # Older gcc versions need -pthread, not just -lpthread + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.1) + find_library(PTHREAD_LIBRARY pthread) + target_link_libraries(ur_loader PRIVATE "-pthread") + endif() + endif() endif() if(WIN32) diff --git a/source/loader/ur_lib.hpp b/source/loader/ur_lib.hpp index 282e5c1c8c..1f0f23658b 100644 --- a/source/loader/ur_lib.hpp +++ b/source/loader/ur_lib.hpp @@ -26,7 +26,6 @@ #include #include #include -#include #include struct ur_loader_config_handle_t_ { diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 4d2fcce81a..9c7060fdbe 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -7743,12 +7743,4 @@ ur_result_t UR_APICALL urUsmP2PPeerAccessGetInfoExp( return exceptionToResult(std::current_exception()); } -namespace { -// This uselessFunc is needed to ensure that pthread is linked correctly against -// ur_loader.so for gcc-9 -void uselessFunc() { - std::thread UselessThread([] {}); -} -} // namespace - } // extern "C"