I can't compile this program!

Mihnea Balta dark_lkml@mymail.ro
Mon Feb 17 16:02:00 GMT 2003


On Monday 17 February 2003 17:58, japan wrote:
> Although I included math.h in the source code, why I must add -lm
> option when we compile one program using math functions???
>
> Ex: gcc -lm -o test test.c
>
> (test.c uses math functions and have already included math.h!)
>
> What libs we must link when compiling like that?

You included the header file, which contains the function prototypes, 
#defines, etc. That's got nothing to do with the linker, which must be told 
to link your code against the math library (libmath). The -lm flag tells it 
to do that. Go learn the difference between a header and a shared library.



More information about the Gcc-help mailing list