g++链接中未定义的引用

Undefined reference in g++ linking

本文关键字:引用 未定义 链接 g++      更新时间:2023-10-16

每次我制作一个新模块并尝试使用以下行将其链接到我的主类(Estudiant.o)时:

g++ -o red1.exe red1.o %OBJETOS_CPP%Estudiant.o

我得到这个错误:

red1.o:red1.cpp:(.text+0xd):对的未定义引用Estudiant::consultar_DNI() const' red1.o:red1.cpp:(.text+0x18): undefined reference to研究者::研究者(int)'red1.o:red1.cpp:(.text+0x25):未定义对的引用Estudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0x74): undefined reference to研究者::afegir_nota(双)'red1.o:red1.cpp:(.text+0x83):未定义对的引用Estudiant::~Estudiant()' red1.o:red1.cpp:(.text+0xa3): undefined reference to研究者::consultar_nota()常量red1.o:red1.cpp:(.text+0xe5):对的未定义引用Estudiant::modificar_nota(double)' red1.o:red1.cpp:(.text+0x10b): undefined reference to Estudiant::Estudiant()'red1.o:red1.cpp:(.text+0x13a):对的未定义引用Estudiant::llegir_estudiant()' red1.o:red1.cpp:(.text+0x144): undefined reference to研究者::te_nota()常量red1.o:red1.cpp:(.text+0x182):对的未定义引用Estudiant::escriure_estudiant() const' red1.o:red1.cpp:(.text+0x18c): undefined reference to Estudiant::~ Estudiant()'red1.o:red1.cpp:(.text+0x19f):对的未定义引用Estudiant::~Estudiant()' c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: red1.o: bad reloc address 0x0 in section.ctors的collect2.exe:错误:ld返回1退出状态

我没有原始的Estudiant.cpp,所以我想这可能是因为编译和链接使用了不同的编译器,但我重新安装了MinGW,我仍然收到这个错误。我还试图替换所有的文件,但没有成功。

我设法获得了Estudiant.o的源代码,并使用该代码编译了它的另一个版本,它成功了。我不知道为什么同一个代码在两台不同的机器上编译,一台工作,另一台不工作。