c语言中关于extern的声明问题
#include <stdio.h>#define MAXLINE 1000
int getline1(void);
void copy(void);
main()
{
int len;
extern int max;
extern char longest[MAXLINE];
max = 0;
while((len = getline1()) > 0)
if(len > max)
{
max = len;
copy();
}
if(max > 0)
printf("%s", longest);
return 0;
}
int getline1(void)
{
int c, i;
extern char line[];
for(i = 0; i < MAXLINE-1 && (c = getchar()) != EOF && c != '\n'; ++i)
line[i] = c;
if(c == '\n')
{
line[i] = c;
++i;
}
line[i] = '\0';
return i;
}
void copy(void)
{
int i;
extern char line[];
extern char longest[];
i = 0;
while((longest[i] = line[i]) != '\0')
++i;
}
上面这段代码是《c语言设计程序》中的,为什么在编译的时候出现$ sudo gcc wbbl.c
/tmp/ccrsZJwV.o: In function `main':
wbbl.c:(.text+0xb): undefined reference to `max'
wbbl.c:(.text+0x16): undefined reference to `max'
wbbl.c:(.text+0x25): undefined reference to `max'
wbbl.c:(.text+0x3f): undefined reference to `max'
wbbl.c:(.text+0x50): undefined reference to `longest'
/tmp/ccrsZJwV.o: In function `getline1':
wbbl.c:(.text+0x7a): undefined reference to `line'
wbbl.c:(.text+0xad): undefined reference to `line'
wbbl.c:(.text+0xba): undefined reference to `line'
/tmp/ccrsZJwV.o: In function `copy':
wbbl.c:(.text+0xe0): undefined reference to `line'
wbbl.c:(.text+0xe6): undefined reference to `longest'
wbbl.c:(.text+0xed): undefined reference to `longest'
collect2: ld returned 1 exit status
为什么这些变量都没有定义啊?