c - gcc 的奇怪编译问题

标签 c gcc compiler-errors

为什么下面的程序用gcc编译,...

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

void foo(double x) {
   printf("%f", sin(2));
}

int main() {
   foo(1);
}

...而这个其他程序没有?

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

void foo(double x) {
   printf("%f", sin(x));
}

int main() {
   foo(1);
}

它给出了以下错误信息:

/tmp/ccVT7jlb.o: nella funzione "foo":
fun.c:(.text+0x1b): riferimento non definito a "sin"
collect2: error: ld returned 1 exit status*

最佳答案

您需要像这样链接到 libm.so

gcc -Wall -Wextra -Werror source.c -o executable -lm

查看-lm

关于c - gcc 的奇怪编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28618638/

相关文章:

c - 传递给 pthread 后结构发生变化

c - 我有两个与 getchar() 和 putchar() 有关的问题

C 连接运算符与 + 运算符

gcc - GCC何时插入异或eax,eax?

swift - 如何使用自定义消息强制 Swift 编译器错误

c - 在 C 中使用带计数器的链表进行数据包嗅探

gcc - 构建 GCC 交叉编译器(从 "Linux"到 "Windows")

c - 如何在我的计算机上启用对 POPCNT 指令/内部指令的支持?

c++ - header 包含和编译器错误

c++ - 如何使用 text.hpp(可选模块)重新编译 OpenCV?