# Trouble in generating 32bit GLFW application on Ubuntu 17.04

**URL:** <https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942>\
**Category:** support\
**Created:** [July 9, 2017, 10:49am UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942 "2017-07-09T10:49:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bharath](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bharath](https://discourse.glfw.org/u/bharath)\
**Post date:** [July 9, 2017, 10:49am UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/1 "2017-07-09T10:49:04Z")

</div>

Hi Everyone,

I’ve been working on a 3D Engine supporting both 32bit and 64bit on Linux. I’m using GLFW and I was able to successfully generate a 64 bit(amd64) application. I used the in-build supplied Cmake stuff to generate GLFW make files and built.

Whenever I try to build a 32bit(i386) application I always run into this error

```
skipping incompatible ../RenderingLibraries/lib/Linux/ when searching for -lglfw
/usr/bin/ld: cannot find -lglfw

```

I understand that the generated [libglfw.so](http://libglfw.so) is of a 64bit version. My question is how to generate 32bit version of [libglfw.so](http://libglfw.so) ?  
I don’t have much experience in building 32 bit for linux. Any help is much appreciated.

Thanks,  
Bharath

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [July 9, 2017, 12:52pm UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/2 "2017-07-09T12:52:34Z")

</div>

[This answer for 32bit compilation on Ubuntu 64bit](http://discourse.glfw.org/t/building-32bit-libraries-on-a-64bit-ubuntu/680/2?u=dougbinks) should hopefully point you in the right direction. Basically you need to add the following to the cmake project:

`set_target_properties(MyTarget PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")`

A quick search for cmake -m32 will also turn up more information for you if you want a different approach.

---

<div class="post-metadata">

**Author:** ![bharath](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bharath](https://discourse.glfw.org/u/bharath)\
**Post date:** [July 12, 2017, 8:45am UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/3 "2017-07-12T08:45:39Z")

</div>

Thanks for your reply. I use Premake for most of my projects and I’m pretty new to CMake building project files. Can you please tell me more about setting target properties as it requires a target to set ? I can’t figure out what the target is.

Also, I tried to add -m32 flags to both Compiler and Linker flags in the CMakeCache.txt and It is now throwing me follow errors  
[1%] Linking C shared library [libglfw.so](http://libglfw.so)  
/usr/bin/ld: cannot find -lXrandr  
/usr/bin/ld: cannot find -lXinerama  
/usr/bin/ld: cannot find -lXxf86vm  
/usr/bin/ld: cannot find -lXcursor

I installed all the above packages using  
sudo apt-get install libx11-dev:i386  
sudo apt-get install libxrandr2:i386  
sudo apt-get install libxinerama1:i386  
sudo apt-get install libxxf86vm1:i386  
sudo apt-get install libxcursor1:i386

Even after installing all those packages I see the same “Cannot find” error.

After installing I observed that in the location /usr/lib/i386-linux-gnu/ I see those 32 bit version of shared libraries. but the compiler isn’t able to detect (May be … ) ? ???

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [July 12, 2017, 9:01am UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/4 "2017-07-12T09:01:57Z")

</div>

I’m now away at a Games conference and so won’t be able to respond until  
next week, but someone else on the forum might be able to help you before  
then.

---

<div class="post-metadata">

**Author:** ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)\
**Post date:** [July 12, 2017, 10:50pm UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/5 "2017-07-12T22:50:06Z")

</div>

Following steps worked for me on 64-bit Ubuntu 16.04:

1. Enable 32-bit architecture:

2. Update apt:

3. Install multiarch compiler, 32-bit libraries & dev packages:

4. Run cmake like this:

It probably would be simpler & easier just to run 32-bit chroot or docker image.

---

<div class="post-metadata">

**Author:** ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)\
**Post date:** [July 12, 2017, 11:21pm UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/6 "2017-07-12T23:21:16Z")

</div>

Worked for me, but I had to set `MATH_LIBARARY` by hand to get the examples to build.

---

<div class="post-metadata">

**Author:** ![bharath](https://avatars.discourse-cdn.com/v4/letter/b/bc8723/32.png) [@bharath](https://discourse.glfw.org/u/bharath)\
**Post date:** [July 14, 2017, 7:45am UTC](https://discourse.glfw.org/t/trouble-in-generating-32bit-glfw-application-on-ubuntu-17-04/942/7 "2017-07-14T07:45:21Z")

</div>

Phew !! Finally I was able to build [libglfw.so](http://libglfw.so), libglfw.so.3 libglfw.so.3.2 32 bit after installing a lot of dependencies !!!

Just to help others I wanted to post here what I did.

In order to build 32-bit glfw libraries on Linux(I used Ubuntu), execute the following commands and install the following list of all dependencies

Commands : ( Much listed by @mmozeiko above )  
1) dpkg–add-architecture i386  
2) sudo apt-get update  
3) sudo apt-get install gcc-multilib libx11-6:i386 libxrandr-dev:i386 libxinerama-dev:i386 libxxf86vm-dev:i386 libxcursor-dev:i386

install packages now

packages :

1. sudo apt-get install libx11-dev:i386
2. sudo apt-get install libxrandr2:i386
3. apt-get install libxinerama1:i386
4. sudo apt-get install libxxf86vm1:i386
5. sudo apt-get install libxcursor1:i386
6. sudo apt-get install libvulkan-dev:i386
7. sudo apt-get install libxrandr-dev:i386
8. apt-get install libxinerama-dev:i386
9. sudo apt-get install libxcursor-dev:i386
10. sudo apt-get install libc-dev:i386
11. sudo apt-get install libgl-dev:i386

last command  
4) cmake -DCMAKE\_C\_FLAGS="-m32" -DCMAKE\_SYSTEM\_LIBRARY\_PATH=/usr/lib/i386-linux-gnu path/to/glfw/source

You can install built libraries using “make install”, but it would just install in /usr/local/lib/.

Make sure to copy all [libglfw.so](http://libglfw.so), libglfw.so.3 and libglfw.so.3.2 files to the /usr/lib/i386-linux-gnu folder as Ubuntu expects it to be in there for building GLFW applications.

Hope this will help somebody 🙂 …

Thank you so much for your assistance guys. I appreciate it 🙂

-Bharath
