<分区>
考虑以下简短的 C
程序:
#include <math.h>
#include <stdio.h>
#define K 20
// int K = 20;
int main() {
printf("%f\n", sqrt(K));
}
这个程序,如给定的那样,用 gcc Foo.c
编译,并产生正确的输出。
但是,如果我们注释掉 #define
行,并注释掉 int K = 20
行,那么我们会得到一个编译时错误 对 sqrt'
的 undefined reference ,只能通过使用 gcc Foo.c -lm
进行编译来修复。
我在 Ubuntu 13.04
上使用 gcc 4.7.3
。