【发布时间】:2011-03-31 11:22:56
【问题描述】:
可能重复:
How to declare a structure in a header that is to be used by multiple files in c?
c代码,头文件问题。
我有一个头文件 (list.h) 定义了两个链表结构,另一个 queue.h 包含了队列的定义。
有一个包含列表和队列的结构体,定义在 list.h 中,因此依赖于 queue.h 文件。
包含所有其他结构的结构在 list.h 文件中定义,处理它的函数在 list.c 文件中定义。因此,这两个文件都需要包含 queue.h。
但是,如果我将它包含在 list.h 和 list.c 文件中,我会收到以下错误。
..\/queue.h:13:16: error: redefinition of 'struct qqq'
..\/queue.h:13:16: note: originally defined here
如果不在其中一个或另一个中,则其他错误导致标题丢失: 它没有定义包含队列的结构。
有没有办法做到这一点...?
【问题讨论】:
-
en.wikipedia.org/wiki/Include_guard 就是你所需要的 ;)
-
我喜欢这个想法(谢谢大家),它非常有意义,但是当我实现它时,我得到
D:\workspace\swap\Debug/../pre boolean remote/swap.c:22: multiple definition of 'main' swap.o:D:\workspace\swap\Debug/../swap.c:22: first defined here的许多功能(可能全部)。试图找到任何明显的原因,但到目前为止没有运气
标签: c file header dependencies