Trouble in generating 32bit GLFW application on Ubuntu 17.04


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 is of a 64bit version. My question is how to generate 32bit version of ?
I don’t have much experience in building 32 bit for linux. Any help is much appreciated.



This answer for 32bit compilation on Ubuntu 64bit 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.


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
/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 … ) ? ???


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


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

  1. Enable 32-bit architecture:

    dpkg --add-architecture i386
  2. Update apt:

    sudo apt-get update
  3. Install multiarch compiler, 32-bit libraries & dev packages:

    sudo apt-get install gcc-multilib libx11-6:i386 libxrandr-dev:i386 \
        libxinerama-dev:i386 libxxf86vm-dev:i386 libxcursor-dev:i386
  4. Run cmake like this:

    cmake -DCMAKE_C_FLAGS="-m32" -DCMAKE_SYSTEM_LIBRARY_PATH=/usr/lib/i386-linux-gnu path/to/glfw/source

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


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


Phew !! Finally I was able to build, 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, and 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 :slight_smile:

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