Compiling Textbook Style Code on Linux
You can write programs on Linux too. It's been a while, but I have had
success in the past. These instructions were last updated in Jan. 2015, but
have not yet been thoroughly tested. You may also be able to do it with a BSD Unix.
With Unix OS's you need to be careful about your graphics card and its drivers. Third-party Open Source drivers usually have poor support for newer versions of OpenGL, so I recommend getting proprietary drivers for AMD and NVIDIA cards. Intel released open source drivers for their hardware which are part of the Linux kernel.
Get freeglut
-
You will need to install freeglut on your system. Your Linux distribution
probably already has freeglut installed or available through the package
manager. Be sure that you have both the libraries and development headers
installed.
For example on Ubuntu Linux or Mint Linux you can get freeglut3 and
freeglut3-dev like this:
sudo apt-get install freeglut3 freeglut3-dev
- If you can't find freeglut packages for your distribution, you can find the
source code on SourceForge:
http://freeglut.sourceforge.net/index.php
untar/gzip it, go into the folder, then type
./configure;make;make install
Get GLEW
-
You also need to install GLEW on your system. Your Linux distribution
probably might have itavailable through the package
manager. Be sure that you have both the libraries and development headers
installed.
For example on Ubuntu Linux or Mint Linux you can get GLEW
freeglut3-dev like this:
sudo apt-get install libglew1.10 libglew-dev
- If you can't find GLEW packages for your distribution, you can find the
source code on SourceForge:
/index.php
untar/gzip it, then move to the project directory, and type:
sudo apt-get install libXmu-dev libXi-dev libgl-dev dos2unix
./configure;make;make install
Compiling and Linking with OpenGL, freeglut, and GLEW
-
You should be able to compile as usual, but you need to link an OpenGL
project against libGL.so and probably also libGLU.so. Freeglut projects also
need to linkd against you need to link against liglew.so. Finally GLEW projects need to link agains libGLEW.so.
Briefly, to compile and link a program that uses all three, use these options
g++ filenname.cpp -lGLEW -lGLU -lGL -lglut