[英]Undefined reference in g++ linking
Every time I make a new module and try to link it to my main class (Estudiant.o)
using this line: 每次我创建一个新模块并尝试使用此行将其链接到我的主类
(Estudiant.o)
:
g++ -o red1.exe red1.o %OBJETOS_CPP%\\Estudiant.o
I get this error: 我收到此错误:
red1.o:red1.cpp:(.text+0xd): undefined reference to
Estudiant::consultar_DNI() const' red1.o:red1.cpp:(.text+0x18): undefined reference to
Estudiant::Estudiant(int)' red1.o:red1.cpp:(.text+0x25): undefined reference toEstudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0x74): undefined reference to
Estudiant::afegir_nota(double)' red1.o:red1.cpp:(.text+0x83): undefined reference toEstudiant::~Estudiant()' red1.o:red1.cpp:(.text+0xa3): undefined reference to
Estudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0xe5): undefined reference toEstudiant::modificar_nota(double)' red1.o:red1.cpp:(.text+0x10b): undefined reference to
Estudiant::Estudiant()' red1.o:red1.cpp:(.text+0x13a): undefined reference toEstudiant::llegir_estudiant()' red1.o:red1.cpp:(.text+0x144): undefined reference to
Estudiant::te_nota() const' red1.o:red1.cpp:(.text+0x182): undefined reference toEstudiant::escriure_estudiant() const' red1.o:red1.cpp:(.text+0x18c): undefined reference to
Estudiant::~Estred1.o:red1.cpp :(。text + 0xd):未定义对
Estudiant::consultar_DNI() const' red1.o:red1.cpp:(.text+0x18): undefined reference to
Estudiant :: Estudiant(int )'red1.o:red1.cpp :(。text + 0x25):未定义引用Estudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0x74): undefined reference to
Estudiant :: afegir_nota (double)'red1.o:red1.cpp :(。text + 0x83):未定义对Estudiant::~Estudiant()' red1.o:red1.cpp:(.text+0xa3): undefined reference to
Estudiant的Estudiant::~Estudiant()' red1.o:red1.cpp:(.text+0xa3): undefined reference to
: :consultar_nota()const'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
Estudiant :: te_nota()const'red1.o:red1.cpp :(。text + 0x182):未定义对Estudiant::escriure_estudiant() const' red1.o:red1.cpp:(.text+0x18c): undefined reference to
::〜Est udiant()' red1.o:red1.cpp:(.text+0x19f): undefined reference toEstudiant::~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: error: ld returned 1 exit statusudiant()'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
〜Estudiant()'的引用Estudiant::~Estudiant()' c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: red1.o: bad reloc address 0x0 in section
:错误:ld返回1退出状态
And I don't have the original Estudiant.cpp so I thought it might be because different compilers were used for compiling and for the link, but I reinstalled MinGW and I'm still getting this error. 而且我没有原始的Estudiant.cpp,所以我认为可能是因为使用了不同的编译器进行编译和链接,但是我重新安装了MinGW,但仍然出现此错误。 I also tried to replace all the files and it didn't work.
我也尝试替换所有文件,但是没有用。
I managed to get the source code of the Estudiant.o and compiled another version of it using the code and it worked. 我设法获得Estudiant.o的源代码,并使用该代码编译了它的另一个版本,并且该代码可以正常工作。 I don't know why the same code was compiled on two different machines and one worked and the other one didn't.
我不知道为什么在两台不同的机器上编译相同的代码,为什么一台可以工作,而另一台却没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.