Building 32bit libraries on a 64bit ubuntu


I’m running the 64bit version of ubuntu 16.04LTS on my computer.
In the first phase of my project I compiled a 64bit executable on it, everything was ok, glfw was doing ok.
But now in the second phase, I have to compile the same program as a 32bit application.

As I’m using ubuntu I need to compile the glfw library from the source code using cmake.

My question now how can I build a 32bit glfw library on a 64bit operating system using cmake.
And can the 64bit glfw3 library and its 32bit equivalent exist next to each other.

In the make file of my program I already specified the -m32, but I think the glfw3 library is still a 64bit library.
When I compile my program I have the following errors:

/usr/bin/ld: skipping incompatible /usr/local/lib/libglfw3.a when searching for -lglfw3
/usr/bin/ld: skipping incompatible //usr/local/lib/libglfw3.a when searching for -lglfw3
/usr/bin/ld: cannot find -lglfw3
/usr/bin/ld: cannot find -lXrandr
/usr/bin/ld: cannot find -lXinerama
/usr/bin/ld: cannot find -lXcursor
/usr/bin/ld: cannot find -lXrender
collect2: error: ld returned 1 exit status
makefile:145: recipe for target ‘bin/SolOS’ failed
make: *** [bin/SolOS] Error 1

As I’m completely new to this 32bit vs 64bit compatibility issue, all help is welcome.


I don’t have any of my Linux environments with me at the moment, but have you tried this stackoverflow answer on 32bit compilation on a 64bit machine with gcc/cmake ?

Alternatively, if you use add_subdirectory( glfw ) to include the glfw cmake project in your projects cmake file then I think the build flag -m32 should carry over. Note you need glfw to be a subdir of your project above where you have the cmakelists.txt file.