读书人

多文件编译的有关问题

发布时间: 2012-02-10 21:27:41 作者: rapoo

多文件编译的问题
如下:

----------------------------------main.c

#include"fish.h"
int main(void)
{
i=0;
printf("%d",linker.key);
getch();
return 0;
}

----------------------------------main.c

----------------------------------fish.h

#include"AQS.c"
#include"AB.c"
#include"LB.c"
#include"val.c"
#include"ID.c"
extern int array[];
extern struct LINK linker;
extern int i;
extern int *p;

----------------------------------fish.h

----------------------------------ID.c

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define NULL 0

----------------------------------ID.c

----------------------------------LB.c
struct LINK
{
int key;
struct LINK *next;
};
struct LINK linker;
linker.key=5;

----------------------------------LB.c

此时无论是win-tc或vc++都会报错...

错误定位在LB.c的最后一行上,即linker.key=5;

不知道为什么.....如果去了那一行,即:

----------------------------------LB.c
struct LINK
{
int key;
struct LINK *next;
};
struct LINK linker;

----------------------------------LB.c

在main中处理这个,即:

----------------------------------main.c

#include"fish.h"
int main(void)
{
i=0;

linker.key=5;
printf("%d",linker.key);
getch();
return 0;
}

----------------------------------main.c

就正确了.....呃...不知道为什么....

如果各位看官知道原因,烦告知...


[解决办法]
在文件a.c中定义函数

C/C++ code
int fun(int a, char b)  //注意不要加static 关键字{   ....} 

读书人网 >C语言

热点推荐