それぞれのファイルを個別にコンパイルしてから、c
それらを1つの実行可能ファイルとしてリンクしようとしています。以下は2つのc
ファイルです:
file1.c
#include <stdio.h>
void display();
int count;
int main() {
printf("Inside the function main\n");
count = 10;
display();
}
file2.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
私はどのような間違いを犯していますか?