I made 2 files which are different from the program above one is temp1.h and another is temp2.c to understand how extern is used. So here is temp1.h
#include<stdlib.h>
typedef struct node * bond;
extern int jk;
页: 1
#include<stdio.h>
#include<temp1.h>
struct node {
int data;
};
int main ()
{
bond t1;
t1=(bond)malloc(sizeof(bond));
t1->data=23;
printf("the data is %d
",t1->data);
jk=0;
printf("The variable jk = %d
",jk);
}
and when I compile these as
cc -I ./ temp2.c
then I get
/tmp/ccdeJCat.o: In function `main :
temp2.c:(.text+0x3c): undefined reference to `jk
temp2.c:(.text+0x46): undefined reference to `jk
collect2: ld returned 1 exit status
我在温1.h中宣布了 j,这样我为什么不能在温2.c中开首?