2011-09-26 93 views
4

構建我的項目時出現一些未定義的引用。下面是生成日誌:OpenGL + GLEW + MinGW應用程序鏈接問題

**** Build of configuration Debug for project test **** 

**** Internal Builder is used for build    **** 
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o src\main.o ..\src\main.cpp 
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o src\test.o ..\src\test.cpp 
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o src\window.o ..\src\window.cpp 
..\src\window.cpp: In member function 'void Window::StartRenderContext()': 
..\src\window.cpp:150:24: warning: NULL used in arithmetic 
..\src\window.cpp:161:28: warning: NULL used in arithmetic 
..\src\window.cpp:174:24: warning: NULL used in arithmetic 
g++ -mwindows -l glew32 -l glew32s -l glu32 -l opengl32 -o test.exe src\window.o src\test.o src\main.o 
src\window.o: In function `ZN6Window18StartRenderContextEv': 
C:\eclipse\workspace\test\Debug/../src/window.cpp:101: undefined reference to `[email protected]' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:102: undefined reference to `[email protected]' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:115: undefined reference to `glewInit' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:125: undefined reference to `[email protected]' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:126: undefined reference to `[email protected]' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:148: undefined reference to `__wglewChoosePixelFormatARB' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:159: undefined reference to `__wglewChoosePixelFormatARB' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:185: undefined reference to `__wglewCreateContextAttribsARB' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:194: undefined reference to `__wglewCreateContextAttribsARB' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:204: undefined reference to `__wglewCreateContextAttribsARB' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:214: undefined reference to `__wglewCreateContextAttribsARB' 
C:\eclipse\workspace\test\Debug/../src/window.cpp:227: undefined reference to `[email protected]' 
collect2: ld returned 1 exit status 
Build error occurred, build is stopped 
Time consumed: 8128 ms. 

這裏是我的鏈接命令:

g++ -mwindows -l glew32 -l glew32s -l glu32 -l opengl32 -o test.exe src\window.o src\test.o src\main.o 

這是正確的嗎?我使用的是glew的64位二進制文​​件(我認爲32位並不意味着什麼)。他們只是想用於視覺工作室嗎?

這裏是包括在我的代碼:

#include "Windows.h" 
#include "GL/glew.h" 
#include "GL/wglew.h" 
#include "GL/gl.h" 
#include "GL/glu.h" 
#include "test.h" 

我使用Eclipse CDT靛藍,MinGW的,Win32的,OpenGL和GLEW。

+0

爲什麼你包括'wglew.h'?你爲什麼在包含'glew.h'後加入'gl.h'? – genpfault

+0

我正在使用wglew初始化wgl,我相信這是專用庫。就gl和glu而言,我將它們包括在希望能夠解決函數調用的問題中。它沒有,所以我可能會嘗試刪除它們。我也會刪除wglew,看看是否可以真正解決這些問題,但我不確定。 – AutoBotAM

+0

好吧,我已經縮小了包括'glew.h'和'wglew.h',我現在也只包括'glew32s.lib',並且定義了'GLEW_STATIC',但我仍然得到了確切的相同的未定義參考!如果有人在MinGW的Eclipse Indigo CDT環境中嘗試使用Glew應用程序,他們可以發佈結果嗎? xD – AutoBotAM

回答

1

我解決了「glew undefined reference」問題。

我的開發環境是在Windows 7(x64)上使用MinGW的eclipse CDT。

的解決方案是以下3個步驟:

  1. 添加源代碼:#define GLEW_STATIC
  2. 添加鏈接標誌:-lglew32s -lopengl32 -lfreeglut
  3. 添加編譯標誌:gcc -DGLEW_STATIC

如果需要的話,你有添加-lglu32 -glut32