当我尝试使用Tiny C 编译器编译源文件时,出现以下错误:
arch/x86/include/asm/ptrace.h:38: error: struct/union/enum already defined
以下是头文件ptrace.h中的第9-68行,我的源文件间接包含:
#ifdef __i386__
struct pt_regs {
unsigned long bx;
unsigned long cx;
unsigned long dx;
unsigned long si;
unsigned long di;
unsigned long bp;
unsigned long ax;
unsigned long ds;
unsigned long es;
unsigned long fs;
unsigned long gs;
unsigned long orig_ax;
unsigned long ip;
unsigned long cs;
unsigned long flags;
unsigned long sp;
unsigned long ss;
};
#else /* __i386__ */
struct pt_regs {
/*
* C ABI says these regs are callee-preserved. They aren't saved on kernel entry
* unless syscall needs a complete, fully filled "struct pt_regs".
*/
unsigned long r15;
unsigned long r14;
unsigned long r13;
unsigned long r12;
unsigned long bp;
unsigned long bx;
/* These regs are callee-clobbered. Always saved on kernel entry. */
unsigned long r11;
unsigned long r10;
unsigned long r9;
unsigned long r8;
unsigned long ax;
unsigned long cx;
unsigned long dx;
unsigned long si;
unsigned long di;
/*
* On syscall entry, this is syscall#. On CPU exception, this is error code.
* On hw interrupt, it's IRQ number:
*/
unsigned long orig_ax;
/* Return frame for iretq */
unsigned long ip;
unsigned long cs;
unsigned long flags;
unsigned long sp;
unsigned long ss;
/* top of stack page */
};
#endif /* !__i386__ */
通过间接包含,我的意思是我的源文件包含一个包含此头文件的不同头文件。 结构未声明两次。出了什么问题?
答案 0 :(得分:0)
在黑暗中拍摄,但尝试对结构进行单一声明,但在预编译指令中只有字段声明。
答案 1 :(得分:0)
我必须放入-nostdinc标志。结构pt_regs在标准包含文件中定义。