On 11/27/05, Matthew Miller <mattdm@xxxxxxxxxx> wrote: > On Sun, Nov 27, 2005 at 10:32:16AM +0200, Dotan Cohen wrote: > > > Right -- "m" isn't an option, but actually the name of the library. Well, > > > actually, the library is "libm.so", but the -l assumes a prefix of lib and a > > > suffix of .so. > > Why doesn't it include the math library when I put at the top of the file: > > # include <math.h> > > A good question for the instructor of your C class, actually. :) > > There's two things going on. First, compiling your code, and second, linking > the resulting binary object files into an executable. Fancy modern compilers > like gcc make that all one step for your convenience. > > The first part, compiling, takes your source code and makes a binary file of > it. If you give gcc the "-c" flag, it'll just compile and not try to link: > > gcc -c hellowworld.c > > and you'll get "hellowworld.o". > > You could then call the linker directly with the command "ld", but it's > easier to use gcc as a front-end again, because it includes a bunch of > default options, so you can conveniently say > > gcc hellowworld.o -o hellowworld > > and get your hellowworld executable. But, the default options it gives > includes the core standard C library, but not necessarily any other > libraries, even very standard ones like the math library. So you have to > give the linker the names of those libraries during the link stage: > > gcc hellowworld.o -lm -o hellowworld > > There's actually no difference between the -l flag and giving the full path > to the libray directly on the link command line, except that the -l flag > conveniently looks in the standard locations (/lib, /usr/lib, whatever else) > and does the lib- -.so magic. > > Turbo C's IDE probably automatically detects the use of these functions and > includes this automatically, but it's doing the same thing behind the > scenes. > > Make more sense now? > Thanks. Yes, most of this information is indeed in the gcc man page, which I have read about half of. That particular man page must be the longest single document on my system- I couldn't finish it! Thank you for the summarization. As for the -o option, I would like to have the compiler output filename.out for filename.c without me having to write it out every time. Is this possible? If the answer to that question lies in the man page, then it is in the second half! Thank you very much for the information! Dotan http://technology-sleuth.com/technical_answer/what_is_a_firewall.html :