好吧,我认为我的问题有点有趣,我想了解我的 Ubuntu 盒子里发生了什么。
我编译并链接gcc -lm -o useless useless.c
了以下无用的代码:
/*File useless.c*/
#include <stdio.h>
#include <math.h>
int main()
{
int sample = (int)(0.75 * 32768.0 * sin(2 * 3.14 * 440 * ((float) 1/44100)));
return(0);
}
到现在为止还挺好。但是当我改变这个:
/*File useless.c*/
#include <stdio.h>
#include <math.h>
int main()
{
int freq = 440;
int sample = (int)(0.75 * 32768.0 * sin(2 * 3.14 * freq * ((float) 1/44100)));
return(0);
}
我尝试使用相同的命令行编译 gcc 响应:
/tmp/cctM0k56.o: In function `main':
ao_example3.c:(.text+0x29): undefined reference to `sin'
collect2: ld returned 1 exit status
并停下来。怎么了?为什么我不能这样编译?
我也试过了sudo ldconfig -v
,没有成功。
提前致谢!
卢卡斯。