C 对“sqrt';”的未定义引用';日志';,

C 对“sqrt';”的未定义引用';日志';,,c,C,当我编译此代码时: #include <stdio.h> #include <math.h> #include <stdlib.h> int main() { char str[] = "3.6"; double res = atof(str); printf("%f\n", sqrt(res)); return 0; } 当我将'sqrt'替换为'log'或'ln'时,会出现

当我编译此代码时:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main() {

    char str[] = "3.6";

    double res = atof(str);

    printf("%f\n", sqrt(res));

    return 0;
}
当我将'sqrt'替换为'log'或'ln'时,会出现相同的错误


编译器:cc(ubuntu8.3.0-6ubuntu1)8.3.0编译时必须链接数学库。将
-lm
标志添加到gcc命令中,在源文件或目标文件之后。

*添加到命令末尾如何使用
CMakeLists.txt
    ====================[ Build | untitled12 | Debug ]==============================
/snap/clion/81/bin/cmake/linux/bin/cmake --build /home/abdo/CLionProjects/untitled12/cmake-build-debug --target untitled12 -- -j 4
[ 50%] Linking C executable untitled12
/usr/bin/ld: CMakeFiles/untitled12.dir/main.c.o: in function `main':
/home/abdo/CLionProjects/untitled12/main.c:11: undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/untitled12.dir/build.make:84: untitled12] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/untitled12.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/untitled12.dir/rule] Error 2
make: *** [Makefile:118: untitled12] Error 2