# How do I add windows APIs to cmake?

**URL:** <https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [June 10, 2020, 5:53pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363 "2020-06-10T17:53:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![imlost](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imlost/32/676_2.png) [@imlost](https://discourse.cmake.org/u/imlost)\
**Post date:** [June 10, 2020, 5:53pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363/1 "2020-06-10T17:53:05Z")

</div>

I’m currently porting a crossplatform project to CMAKE and so far I’ve been able to just use find\_package() or add\_subdirectory() when dealing with third party libraries, but I don’t know how do it with Windows APIs. In particular, I’m trying to add synchapi.h.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [June 10, 2020, 6:34pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363/2 "2020-06-10T18:34:16Z")

</div>

You don’t need to handle it in CMake - just include it in your C/C++ file:

```auto
#include <synchapi.h>

```

It should be in the compiler’s default search path. If it’s not then I’m guessing there’s a problem with your toolchain.

---

<div class="post-metadata">

**Author:** ![imlost](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imlost/32/676_2.png) [@imlost](https://discourse.cmake.org/u/imlost)\
**Post date:** [June 16, 2020, 7:04pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363/3 "2020-06-16T19:04:54Z")

</div>

Looks like I’m lacking something still, getting linker error:

> unresolved external symbol WakeByAddressAll referenced in function

Do I need to specify binary location of windows API? Btw, I specified MT/MTd for windows.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [June 16, 2020, 7:15pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363/4 "2020-06-16T19:15:41Z")

</div>

Looks like a link-time error rather than a compile-time error. You may need to do:

```cmake
target_link_libraries(foo Synchronization)

```

~~though I’m surprised it’s not being linked already.~~ sorry, I looked at [this page](https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-wakebyaddressall) and referenced the DLL, not the .lib.

---

<div class="post-metadata">

**Author:** ![imlost](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imlost/32/676_2.png) [@imlost](https://discourse.cmake.org/u/imlost)\
**Post date:** [June 16, 2020, 8:19pm UTC](https://discourse.cmake.org/t/how-do-i-add-windows-apis-to-cmake/1363/5 "2020-06-16T20:19:41Z")

</div>

That did the job, now I got to deal with some errors regarding macros.
