OpenGL + GLEW + MinGW应用程序链接问题

时间:2011-09-26 00:31:54

标签: windows opengl mingw eclipse-cdt glew

在构建项目时,我得到了一些未定义的引用。这是构建日志:

**** 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 `wglCreateContext@4'
C:\eclipse\workspace\test\Debug/../src/window.cpp:102: undefined reference to `wglMakeCurrent@8'
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 `wglMakeCurrent@8'
C:\eclipse\workspace\test\Debug/../src/window.cpp:126: undefined reference to `wglDeleteContext@4'
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 `wglMakeCurrent@8'
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

这是对的吗?我正在使用64位的glew二进制文件(我认为32s并不意味着什么)。他们只是想与视觉工作室一起使用吗?

这是我的代码中包含的内容:

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

我正在使用Eclipse Indigo CDT,MinGW,Win32,OpenGL和glew。

1 个答案:

答案 0 :(得分:1)

我解决了“glew undefined reference”问题。

我的开发环境是在Windows 7(x64)上使用MinGW进行CDT的日食。

解决方案有以下3个步骤:

  1. 添加源代码:#define GLEW_STATIC
  2. 添加链接器标记:-lglew32s -lopengl32 -lfreeglut
  3. 添加编译标记:gcc -DGLEW_STATIC
  4. 如果需要,您必须添加-lglu32 -glut32