Linux undefined reference to `cos‘

Today, when compiling a piece of code, an error "undefined reference to cos" appears

However, the file already contains the math.h header file. The main reason for the error is that the "cos" function is not defined, or the implementation of the "cos" function is not found. Although we declared the math function library at the beginning of the function, we still did not find it. The realization of cos, then we need to specify the specific path of the sin function.

The location of some system default libraries is under /lib/, we can add the parameter "-lm" when compiling,'l' stands for lib, and'm' stands for math library, which forms "-lm"

Therefore, you can write "gcc test.c -o test -lm" like this

In this way, you can compile and pass

Guess you like

Origin blog.csdn.net/qq_45467083/article/details/109554253
Recommended