簡體   English   中英

g ++鏈接中的未定義參考

[英]Undefined reference in g++ linking

每次我創建一個新模塊並嘗試使用此行將其鏈接到我的主類(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 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):未定義對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退出狀態

而且我沒有原始的Estudiant.cpp,所以我認為可能是因為使用了不同的編譯器進行編譯和鏈接,但是我重新安裝了MinGW,但仍然出現此錯誤。 我也嘗試替換所有文件,但是沒有用。

我設法獲得Estudiant.o的源代碼,並使用該代碼編譯了它的另一個版本,並且該代碼可以正常工作。 我不知道為什么在兩台不同的機器上編譯相同的代碼,為什么一台可以工作,而另一台卻沒有。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM