![](/img/trans.png)
[英]When using fabs, fmin, fmax in a C program, why doesn't the compiler/linker report an error if math.h is not included?
[英]C linker error with gcc and math.h
我收到错误消息,指出pythagorean.so: undefined symbol: cos
。 我正在使用math.h
, stdlib.h
和stdio.h
库以及-lm
开关进行编译。 这里是一个代码片段:
static bool
law_of_cosine_run(esh_command* cmd)
{
if (strcmp(cmd->argv[0], "lawofcosine") == 0) {
printf("The length of the third side is: %f\n",
law_of_cosine(strtol(cmd->argv[1], NULL, 10),
strtol(cmd->argv[2], NULL, 10), strtol(cmd->argv[3], NULL, 10)));
return true;
}
return false;
}
static double
law_of_cosine(double x, double y, double z)
{
return sqrt((x * x) + (y * y) - (2 * x * y * cos(z)));
}
有谁知道为什么会这样? pythagorean.c是我的.c文件。
谢谢
编译时,请确保您键入
gcc *.c -lm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.