how to compile and link C with Mesa on Linux?

Hi, I am a beginner in OpenGL.
I am not quite sure how to compile and link C programs with Mesa, on Linux.

If you could give me some help, I would be very grateful.

Thanks in advance.

Well first of all you need mesa. In case you don’t already have it, go to and download the latest distribution. In the readme files the instructions should be trivial to follow and install mesa on your system.
From then on, try to create a simple OpenGL (maybe + GLUT) program so not much could go wrong when you compile.
If you get function undefined errors gcc can’t find the headers (remember to put capitals in #include <GL/glut.h>.
If you get linker errors (which is the more probable) you need to specify the library to link. In the simplest of cases this should be:

gcc -o glprogram glprogram.c -lglut

Notice the -l it tells the linker to add this library. In case you’re not lucky you need to add the path to the library as well:

gcc -o glprogram glprogram.c -lglut -L/usr/..etc

Check to see where mesa installs the libraries.
Hope the above helps. Post again if you need further help.