在丢弃节中定义错误

Defined in discarded section error

本文关键字:定义 错误      更新时间:2023-10-16

我在头文件myStruct.h中将结构类型定义为struct myStruct {...};

然后我在主体中声明了一个结构对象为:

myStruct s;

以同样的方式在类头中使用一次。

这不起作用,给出一个错误:

`_ZN10myStructC2Ev' referenced in section `...myClass...' 
of.../module.pre.o: defined in discarded section 
`.text._ZN10myStructC2Ev[_ZN10myStructC5Ev]' of .../module.pre.o

如果我在类中只有结构,它就可以工作,但我也需要它在main中。我该如何解决?

将其定义为:

extern myStruct s;

在头文件中。