# Build both 32 and 64bit native binary

**URL:** <https://discuss.gradle.org/t/build-both-32-and-64bit-native-binary/17512>\
**Category:** Help/Discuss\
**Created:** [May 7, 2016, 9:01pm UTC](https://discuss.gradle.org/t/build-both-32-and-64bit-native-binary/17512 "2016-05-07T21:01:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zgmnkv](https://avatars.discourse-cdn.com/v4/letter/z/a87d85/32.png) [@zgmnkv](https://discuss.gradle.org/u/zgmnkv)\
**Post date:** [May 7, 2016, 9:01pm UTC](https://discuss.gradle.org/t/build-both-32-and-64bit-native-binary/17512/1 "2016-05-07T21:01:10Z")

</div>

Hi, does gradle automatically detect possibility to build both 32 and 64 bit native binary on a amd64 linux host?  
If not, what is the easiest way to configure project to build both 32 and 64 bit versions?  
I have 64bit ubuntu 16.04 with gcc, g++, gcc-multilib and g+±multilib installed, but gradle 2.13 creates task to build 64bit binary only. I tried to add diffeternt platforms (x86 and x86\_64) to build script as suggested by documentation, but gradle builds 64 binary for all platforms. Do I have to add gcc options (-m32) manually?

---

<div class="post-metadata">

**Author:** ![snhirsch](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@snhirsch](https://discuss.gradle.org/u/snhirsch)\
**Post date:** [May 24, 2016, 1:16pm UTC](https://discuss.gradle.org/t/build-both-32-and-64bit-native-binary/17512/2 "2016-05-24T13:16:49Z")

</div>

I’m getting the impression that very few developers are using Gradle for C/C++ development.

---

<div class="post-metadata">

**Author:** ![marmax](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/marmax/32/2669_2.png) [@marmax](https://discuss.gradle.org/u/marmax)\
**Post date:** [May 24, 2016, 2:08pm UTC](https://discuss.gradle.org/t/build-both-32-and-64bit-native-binary/17512/3 "2016-05-24T14:08:21Z")

</div>

@snhirsch Unfortunately, I have the same feeling 🙂😉

@zgmnkv Yes, gradle can build both 32 and 64 bit binaries in one build run if appropriate toolchain is installed (AFAIK should be enough to install g{xx}-multilib on ubuntu).

as stated in [72.16.4. Selecting the build types, platforms and flavors for a component](https://docs.gradle.org/2.13/userguide/userguide_single.html#N18C0D):

> For a default component, Gradle will attempt to create a native binary variant for each and every combination of buildType, platform and flavor defined for the project. It is possible to override this on a per-component basis, by specifying the set of targetBuildTypes, targetPlatform and/or targetFlavors.

Just try to specify both “targetPlatform” for the component you want to build:  
e.g.:

> ```
> model {
> platforms {
> x86 {
> architecture "x86"
> }
> x64 {
> architecture "x86_64"
> }
> }
> }
> model {
> components {
> main(NativeLibrarySpec) {
> targetPlatform "x86"
> targetPlatform "x64"
> }
> }
> }
> 
> ```

Also, check the samples (also in gradle-all distribution):  
[https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/target-platforms/build.gradle](https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/target-platforms/build.gradle)  
or  
[https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/variants/build.gradle](https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/variants/build.gradle)

If you still have problems, share your build.gradle (or at least relevant part of it), I might help you.
