Skip to main content
1 of 4
jdhao
  • 29.5k
  • 23
  • 160
  • 323

Note that -lm may not always need to be specified even if you use some C math functions.

For example, the following simple program:

#include <stdio.h> #include <math.h> int main() { printf("output: %f\n", sqrt(2.0)); return 0; } 

can be compiled and run successfully with the following command:

gcc test.c -o test 

Tested on gcc 7.5.0 (on Ubuntu 16.04) and gcc 4.8.0 (on CentOS 7).

The post here gives some explanations:

The math functions you call are implemented by compiler built-in functions

jdhao
  • 29.5k
  • 23
  • 160
  • 323