Building OpenGL/GLUT Programs


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.

If you're interested in using GLFW instead of GLUT, please refer to the course note Building OpenGL/GLFW Apps. 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.


Ubuntu 14.04.1 LTS (Trusty Tahr), 12.10, 12.04.5 LTS (Precise Pangolin)
Fedora 15
Red Hat Enterprise Linux Workstation release 6.3 (Santiago) 2.6.32-279.el6.x86_64
gcc: 4.8.2, 4.7.2, 4.6.3, 4.4.6
Eclipse 3.7.2-1 (Indigo), 3.6.1 (Helios), 3.2.0 (Callisto)

Mac OS X:

Yosemite 10.10.5, Mavericks 10.9.4, Lion 10.7.2, SnowLeopard 10.6.4, Leopard 10.5.8, Tiger 10.4.11
Darwin 14.5.0, 13.3.0, 11.2.0, 10.4.0, 9.8.0, 8.11.0
Xcode: 6.4, 5.1.1, 4.2.1, 3.2.4, 3.1.2, 2.0
gcc: 4.2.1, 4.0.1, 4.0.0
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.66.0svn), 5.1 (clang-503.0.40) (based on LLVM 3.4svn)


8.1 Enterprise, 7 Enterprise, Vista x64 EE SP2 (Build 6002), Vista EE SP2 (Build 6002), XP PE SP3 5.1 (Build 2600)
Visual Studio 2013 12.0.30723.00 Update 3, 2012 11.0.51106.01 Update 1, 2010 10.0.420219.1 SP1Rel, 2008 9.0.21022.8.RTM
.NET Framework 4.5.51641, 4.5.50709, 4.0.30319 SP1Rel, 3.5 SP1


1.7.31-3 (64 bit NT-6.3)
compiler tool chains:
  x86_64-pc-cygwin: gcc 4.8.3 (to generate 64-bit Win32 apps)
  i686-pc-cygwin: gcc 4.8.3 (to generate 32-bit Win32 apps)
  i686-pc-mingw32: gcc 4.7.3 (original MinGW to generate 32-bit Win32 apps)
  i686-w64-mingw32: gcc 4.8.3 (MinGW w64 to generate 32-bit Win32 apps)
  x86_64-w64-mingw32: gcc 4.8.3 (MinGW w64 to generate 64-bit Win64 apps)

Install Cygwin/X11 by downloading and running its
setup program. If you're installing 64-bit version, x86_64-pc-cygwin is the compiler toolchain, i.e., compiler, linker, archiver, etc. you get by default. As installed, Cygwin builds X11 (OpenGL/GLX) apps instead of native Windows (OpenGL/WGL) apps. Unfortunately GLX programs on Cygwin that use buffer object segfault on the call to glBindBuffer() and those that use shaders segfault on the call to glCreateProgram(). So we'll build WGL apps instead. The compiler toolchain that comes with Cygwin can build WGL apps (see Building OpenGL/GLFW Apps), but unfortunately there is no GLUT library that works with it. The available freeglut binaries for MinGW makes duplicate calls to the display callback hanlder as noted above. The Nvidia's GLUT binaries were evidently not compiled to support large memory model, resulting in "relocation truncated to fit" error messages from the linker. Fortunately, the MinGW x86_64 compiler toolchain can work with the Nvidia's GLUT libraries, so we'll use this toolchain instead of the native Cygwin toolchain.

On 64-bit Cygwin, you can choose to build either 32- or 64-bit apps. If you use static libraries, you can set up Cygwin to support both. If you want to build 32-bit apps, you have three toolchains to choose from (see above for a brief summary of each). Use the Cygwin setup program to install your toolchain of choice:


use the following labels, respectively, in place of YOUR_TOOLCHAIN above: i686-pc-cygwin, i686-pc-mingw32, or i686-w64-mingw32. For i686-pc-cygwin, the subdirectory under sys-root is called usr instead of mingw.

References not cited:

Last updated: Sep. 23, 2015 by Sugih Jamin
Thanks to D. Kohler for corrections.