# Build for 32 and 64 bit

**URL:** <https://discourse.cmake.org/t/build-for-32-and-64-bit/2329>\
**Category:** Code\
**Tags:** os:windows, gen:ninja\
**Created:** [December 9, 2020, 7:05pm UTC](https://discourse.cmake.org/t/build-for-32-and-64-bit/2329 "2020-12-09T19:05:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![R030t1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@R030t1](https://discourse.cmake.org/u/R030t1)\
**Post date:** [December 9, 2020, 7:05pm UTC](https://discourse.cmake.org/t/build-for-32-and-64-bit/2329/1 "2020-12-09T19:05:19Z")

</div>

Due to targeting certain features of Windows the 32 bit binaries must be generated even on a 64 bit system. What is the best way to do this? I’d like to have it happen with one build system invocation, but am unsure of what is normally done.

I’m running under MSYS2 and would prefer to use the MinGW compiler toolchains.

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [December 9, 2020, 7:10pm UTC](https://discourse.cmake.org/t/build-for-32-and-64-bit/2329/2 "2020-12-09T19:10:09Z")

</div>

@ben.boeckel I think cmake would benefit from explicit documentation on building 32/64-bit binaries.

Because I’ve seen this same question asked many times now on stackoverflow and this discourse website.  
It seems to be a topic of confusion for many new cmake developers.

---

<div class="post-metadata">

**Author:** ![R030t1](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@R030t1](https://discourse.cmake.org/u/R030t1)\
**Post date:** [December 9, 2020, 7:28pm UTC](https://discourse.cmake.org/t/build-for-32-and-64-bit/2329/3 "2020-12-09T19:28:59Z")

</div>

I’ve found a few ways to do it but it seems to depend on toolchain. In my case, ninja doesn’t seem to support specifying a bitness for the target, and running cmake under the 32 bit MSYS2 shell produces ninja build files that try to use the 64 bit toolchain.

---

<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:** [December 9, 2020, 7:32pm UTC](https://discourse.cmake.org/t/build-for-32-and-64-bit/2329/4 "2020-12-09T19:32:24Z")

</div>

> [@YMba9g8j9CJp0wLoQf5y](#):
>
> I think cmake would benefit from explicit documentation on building 32/64-bit binaries.

Agreed. I’m not sure of the best place to put it within the docs (the tutorial? with the generator at hand?), but please open an issue about it (links to questions and/or experiences would be helpful).

> [@R030t1](#):
>
> under the 32 bit MSYS2 shell produces ninja build files that try to use the 64 bit toolchain.

Do you mean the 64-bit-generating toolchain or a toolchain that is itself compiled as 64bit binaries? I think MSYS2 might need `-m32` or something to make it compile 32-bit. Though I’ve not done so in years, so my memory may be flaky here.
