I can't compile this program!
Dockeen
dockeen@mchsi.com
Mon Feb 17 19:59:00 GMT 2003
> Although I included math.h in the source code, why I must add -lm
> option when we compile one program using math functions???
You must remember what a header is. It is a data file that contains
definitions of what functions take and give back. There is no code
in a header file. The guts of the math functions are contained in
the math library, and the command -lm is what links (makes available)
that code.
Note also that it is not just enough to have the library in the
library link search path, you have to link it through the link command.
Also, one other thing that fouls up folks is that, if you have a
library names something like xyz, the library file will probably have a
name something like libxyz.a, but when you do the link, you use the
library name, not the library file name.
Wayne Keen
More information about the Gcc-help
mailing list