[prog] OpenGL/Mesa/Glut

James Sutherland jas at spamcop.net
Fri Jun 20 12:34:46 EST 2003


From: "Sue Stones" <suzo at bigpond.net.au>

> Well further searches on Google have produced that I need to set CFLAGS
thus
>
> "CFLAGS=-I/usr/X11R6/Include"
>
> "/usr/X11R6/Include" is the directory, what is the -I before that?

The -I flag tells the C compiler to *I*nclude that directory in the list it
searches for header files.

> Also, is anyone able to explain CFLAGS?  It is some sort of enviroment
> variable, used by the C compiler I think.  How do I get the compiler to
use
> it?

This is normally done in the Makefile - you'll find an entry telling make
how to compile C code into Object code (.o files), something like this:

.c.o:
    $(CC) $(CFLAGS) -c $< -o $@

This looks horrible, but just tells make to run the C compiler (identified
by the $CC variable, for C Compiler), with the value of $CFLAGS appended.
The "-o $@" tells the compiler what to name the output file; likewise, "-c
$<" tells it which file to compile.

> What is the best way to set CFLAGS.

On the command line, just put it before the make command, like so:

$ CFLAGS="-I/usr/X11R6/Include -march=pentium3 -O2 -pipe" make all

The extra bits there tell gcc to optimise at level 2 (-O2) for a Pentium 3
architecture, and use pipes instead of temporary files. Be careful with the
quotes, otherwise you can end up trying to run a command called -O2, which
probably isn't the desired result ;-)


James.



More information about the Programming mailing list