简体   繁体   English

gcc和math.h的C链接器错误

[英]C linker error with gcc and math.h

I am getting an error stating pythagorean.so: undefined symbol: cos . 我收到错误消息,指出pythagorean.so: undefined symbol: cos I am compiling with the math.h , stdlib.h , and stdio.h libraries and the -lm switch. 我正在使用math.hstdlib.hstdio.h库以及-lm开关进行编译。 Here a code snippet: 这里是一个代码片段:

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)));
}

Does anyone know why this would occur? 有谁知道为什么会这样? pythagorean.c is my .c file. pythagorean.c是我的.c文件。

Thanks 谢谢

编译时,请确保您键入

gcc *.c -lm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM