小编Ana*_*DIL的帖子

对 `sin' 的未定义引用,即使我使用 <math.h> 和 -lm

我注意到当我使用sin内部函数时,编译器无法识别它,这是一个例子:

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

float sinus(float a){
    return sin(a);}

int main(int argc, char **argv)
{
    double a = sinus(2);
    printf("%f \n", sin(2));
    printf("%f", a);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我直接在 main 中使用它,它工作正常,但在用户定义的函数中,它给了我这个错误undefined reference to sin

对于编译,我使用gcc -Wall -lm -lc -lgcc -o "%e" "%f".

c linker-errors undefined-reference

1
推荐指数
1
解决办法
578
查看次数

标签 统计

c ×1

linker-errors ×1

undefined-reference ×1