【发布时间】:2015-02-04 04:12:58
【问题描述】:
我正在努力学习足够多的 c 来满足我偶尔编写简单程序来回答我遇到的特定问题的需要。我一直在学习教程并使用 Geany 以方便使用。相反,我似乎无法运行最简单的程序。这是我的源代码:
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
int x, y;
double c, sqr_c;
for (x = 10; x <= 31; x++)
{
for (y = 10; y <= 31; y++)
{
c = 1000 * x * x + y * y;
sqr_c = sqrt(c);
printf ("%f\n", sqr_c);
}
}
return 0;
}
它编译得很好(gcc -c)但是当我尝试构建一个可执行文件时,我得到:
gcc "concsqr.c" -Wall -o "concsqr" (in directory: /home/chip)
/tmp/cccSmdZS.o: In function `main':
concsqr.c:(.text+0x4b): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
Compilation failed.
我读过一些关于确保链接器可以找到定义 sqrt() 的库的内容,但我不知道该怎么做,而且它不会在标准位置吗?为什么链接器不知道它在哪里?它是 c 的标准库。
【问题讨论】: