简体   繁体   中英

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:

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 to Estudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0x74): undefined reference to Estudiant::afegir_nota(double)' red1.o:red1.cpp:(.text+0x83): undefined reference to Estudiant::~Estudiant()' red1.o:red1.cpp:(.text+0xa3): undefined reference to Estudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0xe5): undefined reference to Estudiant::modificar_nota(double)' red1.o:red1.cpp:(.text+0x10b): undefined reference to Estudiant::Estudiant()' red1.o:red1.cpp:(.text+0x13a): undefined reference to Estudiant::llegir_estudiant()' red1.o:red1.cpp:(.text+0x144): undefined reference to Estudiant::te_nota() const' red1.o:red1.cpp:(.text+0x182): undefined reference to Estudiant::escriure_estudiant() const' red1.o:red1.cpp:(.text+0x18c): undefined reference to Estudiant::~Est udiant()' red1.o:red1.cpp:(.text+0x19f): undefined reference to 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: error: ld returned 1 exit status

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. 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. I don't know why the same code was compiled on two different machines and one worked and the other one didn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM