我正在尝试分别编译每个c
文件,然后将它们链接在一起作为单个可执行文件。以下是2个c
文件:
文件1.c
#include <stdio.h>
void display();
int count;
int main() {
printf("Inside the function main\n");
count = 10;
display();
}
文件2.c
#include <stdio.h>
extern int count;
void display() {
printf("Sunday mornings are beautiful !\n");
printf("%d\n",count);
}
但是当我尝试编译它们时,我得到了一些错误:
当我编译 file1.c
gcc file1.c -o file1
/tmp/ccV5kaGA.o: In function `main':
file1.c:(.text+0x20): undefined reference to `display'
collect2: ld returned 1 exit status
当我编译 file2.c
gcc file2.c -o file2
/usr/lib/gcc/i686-redhat-linux/4.6.3/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/tmp/cczHziYd.o: In function `display':
file2.c:(.text+0x14): undefined reference to `count'
collect2: ld returned 1 exit status
我犯了什么错误?