【发布时间】:2013-04-15 14:04:32
【问题描述】:
我有 4 个文件 = pic.h、main.c、framehandle.c 和 framehandle.h
pic.h 和 framehandle.h 都包含在我的主目录中:
#include "pic.h"
#include "framehandling.h"
pic.h 具有以下结构定义。
struct f
{
unsigned sleep : 1;
unsigned push : 1;
unsigned rx : 1;
unsigned tx : 1;
unsigned validPacket : 1;
};
我在我的 main.c 文件中使用
声明了这个结构struct f flag;
当我尝试在 framehandle.c 中使用它时,我得到一个我理解的未声明的错误。
为了解决这个问题,我在 framehandle.h 中添加了以下内容:
extern struct f flag;
但是编译器仍然抱怨没有在 framehandle.c 中声明标志
我做错了什么? 不会 extern struct f 标志;应该告诉编译器在其他地方寻找声明? 将它放在主题标题中不是正确的位置吗?
--编辑--
我正在添加包含文件和变量声明的序列
#include "pic.h"
#include "framehandling.h"
struct f flag;
void main(void)
{ }
【问题讨论】:
-
framehandle.c 是否包含 pic.h?确切的编译器错误是什么?
-
framehandle.c 确实包含 pic.h。确切的编译器错误是#framehandling.c:97: error: 'flag' undeclared (first use in this function)
-
也许是个愚蠢的问题,但
framehandle.c是否包含framehandle.h? -
@BryanOlivier 是的,Bryan 确实如此
-
然后尝试查看
framehandle.c的预处理器输出(gcc的选项-E),看看它是否确实包含extern struct f flag声明。你的main.c提到framehandling.h而你的文本的其余部分提到framehandle.h。
标签: c