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.


[QUOTE=Bharath;1287770]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 ?[/QUOTE]

The easiest thing to do is see if there are 32-bit GLFW package available in your distro’s package manager. If so, just install them instead of building them. There may be one package for libs and one for devel (headers).

If not, you’ll need to build GLFW for 32-bit. It uses CMake, so for best results, websearch “cmake 32-bit build” and/or “ubuntu 32-bit build”. I’d post some notes on how to do this with OpenSuSE, but that might not be much use to you.

The main flag to look for in the directions is adding “-m32” to the compiler command line. For instance, here’s a solution for Ubuntu that might work for you. Try doing this before you run cmake: Building a 32-bit app in 64-bit Ubuntu.

Just like for all debian-like distributions, you’ll first need to enable multi-arch.
Then you’ll have to install all 32-bit packages required for building and linking with 32 binaries. This will include glfw, GL, X11 and probably many/several other packages.
And after do what Dark Photon told about Building.

Sample code: the sample Makefile and source code build a simple line drawing application and runs on Linux, Mac OS X, and Windows platforms. You can also try out some examples with buffer objects and shaders.
For instructions on how to build GLUT programs, please refer to the course note Building OpenGL/GLUT Programs. Please let me know if you have any correction or addition. Thanks.
To find out how to specify command line options, add to header file search path, and link with libraries such as glew, expat, jpeg, and png, see the course note on these topics.

version: Ubuntu 14.04.1 LTS (Trusty Tahr), 12.04.5 LTS (Precise Pangolin)
gcc: 4.8.2, 4.6.3
Eclipse 3.7.2-1 (Indigo)

First install GLFW’s dependencies, including OpenGL/Mesa:

sudo apt-get install cmake xorg-dev libglu1-mesa-dev

You must have sudo privileges. (On Red Hat, you’ll need to install cmake28 instead.)
You should now have:
At the time of writing, the GLFW package one gets with apt-get is version 2.7 whereas we’re using version 3.0.4. So we need to install GLFW from source. Unzip the source file and change your working directory to the glfw-3.0.4 directory. Install GLFW:

cd glfw-3.0.4
cmake -G "Unix Makefiles"
sudo make install

You should now have:
In your OpenGL source files, include the following line:

#include <GLFW/glfw3.h>

You don’t need to include gl.h as it is already included in glfw3.h.
For an example, see the provided sample source code.
If you want to include glu.h automatically, set the -DGLFW_INCLUDE_GLU compiler flag.
To make a GLFW application on the command line, use the following linker options:
-lglfw3 -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread
The last three libraries are needed on Ubuntu 14.04.1.

Eclipse 3.7.2 project (graphical step-by-step):
To install Eclipse:

sudo apt-get install eclipse eclipse-cdt

Start up Eclipse and choose your workspace, click “OK” (Fig. 1)
Open the C/C++ perspective: on the main menu select “Window→Open Perspective→C/C++” (Fig. 2). If the C/C++ perspective is not available, choose “Other…” and it should show up in the window that pops up.

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 :

  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 :

sudo apt-get install libx11-dev:i386
sudo apt-get install libxrandr2:i386
apt-get install libxinerama1:i386
sudo apt-get install libxxf86vm1:i386
sudo apt-get install libxcursor1:i386
sudo apt-get install libvulkan-dev:i386
sudo apt-get install libxrandr-dev:i386
apt-get install libxinerama-dev:i386
sudo apt-get install libxcursor-dev:i386
sudo apt-get install libc-dev:i386
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.

follow this link for more information
Hope this will help somebody :slight_smile:

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


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.