0
votes

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 toEstudiant::Estudiant(int)' red1.o:red1.cpp:(.text+0x25): undefined reference to Estudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0x74): undefined reference toEstudiant::afegir_nota(double)' red1.o:red1.cpp:(.text+0x83): undefined reference to Estudiant::~Estudiant()' red1.o:red1.cpp:(.text+0xa3): undefined reference toEstudiant::consultar_nota() const' red1.o:red1.cpp:(.text+0xe5): undefined reference to Estudiant::modificar_nota(double)' red1.o:red1.cpp:(.text+0x10b): undefined reference toEstudiant::Estudiant()' red1.o:red1.cpp:(.text+0x13a): undefined reference to Estudiant::llegir_estudiant()' red1.o:red1.cpp:(.text+0x144): undefined reference toEstudiant::te_nota() const' red1.o:red1.cpp:(.text+0x182): undefined reference to Estudiant::escriure_estudiant() const' red1.o:red1.cpp:(.text+0x18c): undefined reference toEstudiant::~Estudiant()' 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.

1
what is the result of nm %OBJETOS_CPP%\Estudiant.o?StarPinkER
And the Estudiant.o is recent, so it contains those functions referenced in the error messages?Some programmer dude
@billz It's Windows. Different syntax for shell vars.us2012
it doesn't matter i tried to put the Estudiant.o file in the same directory and again the same erro.Buradi

1 Answers

0
votes

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.