我涉足Python一年,並且正在啓動C++,因此我是一個noob。我安裝了MinGW,並且一切正常,直到我安裝了freeglut。當我運行下面的代碼:MinGW和GLUT未定義引用'_imp ____ glutInitWithExit @ 12'
#include <gl/glut.h>
int main()
{
return 0;
}
使用:
C:\code\cpp>g++ GLtest1.cpp
我得到這個:
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x1c): undefined
reference to `[email protected]'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x3e): undefined
reference to `[email protected]'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x60): undefined
reference to `[email protected]'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\U
ser\AppData\Local\Temp\ccABWOyv.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
我安裝並試圖解決問題重新安裝MinGW的幾次,但無濟於事。我嘗試使用
#include <windows.h>
以及。我嘗試安裝64位.dll文件 - 什麼也沒有。如果任何人以前遇到過這種情況,或者對我的問題很熟悉,那麼一些幫助是值得歡迎的。謝謝。我猜我需要用「鏈接」做些什麼,但我真的不明白爲什麼「glut.h」應該與「gl.h」或「glu.h」不同。所以這樣做!
更新:
我試圖聯繫一些事情。首先我做到了這一點:
C:\code\cpp>g++ -c -o GLtest1.exe GLtest1.cpp -I"C:\MinGW\include"
它工作得很好。沒有錯誤。然後我試圖鏈接東西,並最終出現錯誤:
C:\code\cpp>g++ -o GLtest1.exe -L"C:\MinGW\lib" -lglut32 -opengl32
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot fin
d -lglut32
collect2.exe: error: ld returned 1 exit status
這裏的任何想法?要將glut32.dll存在於兩個System32下和SysWOW64中
dll文件是一個動態加載的庫(在運行時需要它)。當您鏈接您的應用程序時,您需要鏈接靜態庫(擴展名爲.a或.lib的文件)。你可以通過-L switch來告訴編譯器在哪裏尋找靜態庫(類似於-I頭)。 – tumdum