0
我收到一個錯誤,指出pythagorean.so: undefined symbol: cos
。我正在編譯math.h
,stdlib.h
和stdio.h
庫和-lm
開關。這裏的代碼片段:C與gcc和math.h的鏈接器錯誤
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文件。
感謝
你把'-lm'所有源之前或之後和目標文件?它需要在之後。 – zwol