This does not have so much to do with gcc as it does with the linker.
Originally Posted by rags_to_riches
LinuxSmith, have a look at the ld(1) man page, either on your own system, or here. Do a search for this (read the paragraph that follows it):
It is not so simple as that - for any library that is not standard, you will have to use the -l switch to tell the linker to look for something that is not standard. For example, when compiling OpenGL (with SDL) stuff under linux, you would see lots of -l switches:
Originally Posted by LinuxSmith
rags_to_riches is correct though - the man pages for the functions you are using ought to tell you when you need to use a switch like that.
-lglut -lXext -lX11 -lXmu -lXi -lGL -lGLU -lm -lSDL -lSDL_mixer
As an aside, compile the following program, (using the -lm switch), and then run it with ldd.
As an example, this is what I get:
double base = 2.0;
double exp = 3.0;
printf("2^3=%.0f\n", pow(base, exp));
As you can see, my program needed libm, which is why I needed to use -lm.
~/cprogs/board> gcc -Wall -Wextra -o demo -lm demo.c
~/cprogs/board> ldd ./demo
linux-vdso.so.1 => (0x00007fff5bfff000)
libm.so.6 => /lib64/libm.so.6 (0x00007f7d9ca63000)
libc.so.6 => /lib64/libc.so.6 (0x00007f7d9c703000)
I am not sure why math.h is considered non-standard - it seems to me that this is a carry over from old Unix behaviour that was long since unnecessary. You can read a little more about some of those quirks (though no explanation as to why) in the FAQ (follow the links through as well).
Edit: There is a discussion on stackoverflow about why we still need to manually link libm. Lots of ideas to consider, if nothing else. Read it here.