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 gcc test.c -o test It was 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
See also: