What is the meaning of -lm in gcc?

Viewed 31970

When i compile some c codes with gcc, it neads adding -lm. Fore example, when i want to use fmax in my program,must be using the following command:

gcc myprogram.c -lm

I don't understand what happen to my program by adding -lm? what does -lm mean?

Thanks.

2 Answers

TLDNR: math.h is not a part of the standard C library, so you have to link to it!

-llibrary searches the library library while linking. The m stands for libm, the library that contains <math.h>. For more information, see these couple links.

@luantkow's answer is really good but long! Here's a short version if you don't want to read! ¯\_(ツ)_/¯

Related