CMake 3.24 FindThreads adds -lpthread to link args for MSVC
We recently had a problem with our builds using CMake 3.24.2 and MSVC.
LINK : warning LNK4044: unrecognized option '/lpthreads'; ignored [X.vcxproj]
LINK : error LNK1218: warning treated as error; no output file generated [X.vcxproj]
It looks like the issue has been encountered before and resolved in #23829 (closed) but we are still having the issue.
For now, I've created a modified version of FindThreads.cmake with lines commented out. Hopefully this should give you the info needed to resolve properly.
--- C:/Program Files/CMake/share/cmake-3.24/Modules/FindThreads.cmake Thu Oct 6 11:07:14 2022
+++ C:/Users/gavinkinsey/Documents/src/X/scripts/cmake/CMakeModules/FindThreads.cmake Thu Oct 6 10:58:28 2022
@@ -176,8 +176,8 @@
if(CMAKE_SYSTEM MATCHES "GHS-MULTI")
_threads_check_lib(posix pthread_create CMAKE_HAVE_PTHREADS_CREATE)
endif()
-_threads_check_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE)
-_threads_check_lib(pthread pthread_create CMAKE_HAVE_PTHREAD_CREATE)
+#_threads_check_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE)
+#_threads_check_lib(pthread pthread_create CMAKE_HAVE_PTHREAD_CREATE)
if (NOT THREADS_PREFER_PTHREAD_FLAG)
_threads_check_flag_pthread()
If you need any more info or tests running please let me know, happy to help.
Edited by Gavin Kinsey