# How to use pthread win32 with Cmake

**URL:** <https://discourse.cmake.org/t/how-to-use-pthread-win32-with-cmake/3004>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [March 24, 2021, 10:28am UTC](https://discourse.cmake.org/t/how-to-use-pthread-win32-with-cmake/3004 "2021-03-24T10:28:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TharinduBalasooriya](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tharindubalasooriya/32/1317_2.png) [@TharinduBalasooriya](https://discourse.cmake.org/u/TharinduBalasooriya)\
**Post date:** [March 24, 2021, 10:28am UTC](https://discourse.cmake.org/t/how-to-use-pthread-win32-with-cmake/3004/1 "2021-03-24T10:28:49Z")

</div>

Can anyone tell me how to add pthread win32 to program the use CMake to build I added the following to Cmake List but still not working

```auto
cmake_minimum_required(VERSION 3.5)
project(FlexibleComputerLanguage)

set(CMAKE_CXX_STANDARD 17)

set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(Threads REQUIRED)

include_directories("C:/Users/Tharindu/Downloads/Compressed/pthread")
include_directories("C:/Users/Tharindu/Downloads/Compressed/pthread/x86")

target_link_libraries(FlexibleComputerLanguage1 Threads::Threads)

```

But I am getting the following error

```auto
Command.cpp.obj : error LNK2019: unresolved external symbol "char * __cdecl strptime(char const *__restrict,char const * __restrict,struct tm *__ restrict)" (?strptime@@YAPADPIBD0PIAUtm@@@Z) referenced in function "private: class Entity * __thiscall Command::ExecuteStringCommand(unsigned long,class Entity *,class Entity *)" (?ExecuteStringCommand@Command@@AAEPAVEntity@@KPAV2@0@Z)
MongoTP.cpp.obj : error LNK2001: unresolved external symbol "char * __cdecl strptime(char const *__restrict,char const * __restrict,struct tm *__ restrict)" (?strptime@@YAPADPIBD0PIAUtm@@@Z)
main.cpp.obj : error LNK2019: unresolved external symbol __imp__ pthread_create referenced in function __catch$?processSlave@@YAPAXPAX@Z$0
main.cpp.obj : error LNK2019: unresolved external symbol __imp__ pthread_join referenced in function __catch$?processSlave@@YAPAXPAX@Z$0
main.cpp.obj : error LNK2019: unresolved external symbol __imp__ pthread_mutex_init referenced in function __catch$?processSlave@@YAPAXPAX@Z$0
main.cpp.obj : error LNK2019: unresolved external symbol __imp__ pthread_mutex_lock referenced in function __catch$?processTDPQuery@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@AAV?$GenericDocument@U?$UTF8@D@rapidjson@@V?$MemoryPoolAllocator@VCrtAllocator@rapidjson@@@2@VCrtAllocator@2@@rapidjson@@@Z$4
main.cpp.obj : error LNK2019: unresolved external symbol __imp__ pthread_mutex_unlock referenced in function __catch$?processTDPQuery@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@AAV?$GenericDocument@U?$UTF8@D@rapidjson@@V?$MemoryPoolAllocator@VCrtAllocator@rapidjson@@@2@VCrtAllocator@2@@rapidjson@@@Z$4
FlexibleComputerLanguage1.exe : fatal error LNK1120: 6 unresolved externals

```

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [March 25, 2021, 6:18pm UTC](https://discourse.cmake.org/t/how-to-use-pthread-win32-with-cmake/3004/2 "2021-03-25T18:18:31Z")

</div>

`FindThreads` returns what it finds. You’re then interposing pthreads headers into your executable after `Threads::Threads` has been found (probably without finding pthreads). You can use the `CMAKE_USE_PTHREADS_INIT` variable after `find_package(Threads)` to see if you have a pthreads-compatible thread implementation.
