windows OpenGL + GLEW + MinGW 应用程序链接问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7549594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenGL + GLEW + MinGW application linking issue
提问by AutoBotAM
I'm getting some undefined references when building my project. Here's the build log:
在构建我的项目时,我收到了一些未定义的引用。这是构建日志:
**** 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.
Here's my link command:
这是我的链接命令:
g++ -mwindows -l glew32 -l glew32s -l glu32 -l opengl32 -o test.exe src\window.o src\test.o src\main.o
Is this correct? I'm using the 64-bit binaries of glew (I think the 32s don't mean anything). Were they only meant to be used with visual studio?
这样对吗?我正在使用 64 位的 glew 二进制文件(我认为 32 没有任何意义)。它们是否只打算与 Visual Studio 一起使用?
Here's the includes in my code:
这是我的代码中的包含:
#include "Windows.h"
#include "GL/glew.h"
#include "GL/wglew.h"
#include "GL/gl.h"
#include "GL/glu.h"
#include "test.h"
I am using Eclipse Indigo CDT, MinGW, Win32, OpenGL, and glew.
我正在使用 Eclipse Indigo CDT、MinGW、Win32、OpenGL 和 glew。
回答by nao
I solved "glew undefined reference" problems.
我解决了“glew undefined reference”的问题。
My development environment is eclipse CDT with MinGW on Windows 7 (x64).
我的开发环境是在 Windows 7 (x64) 上使用 MinGW 的 Eclipse CDT。
The solution is the following 3 steps:
解决方法是以下3个步骤:
- Add source code:
#define GLEW_STATIC
- Add linker flag:
-lglew32s -lopengl32 -lfreeglut
- Add compiling flag:
gcc -DGLEW_STATIC
- 添加源代码:
#define GLEW_STATIC
- 添加链接器标志:
-lglew32s -lopengl32 -lfreeglut
- 添加编译标志:
gcc -DGLEW_STATIC
If needed, you have to add -lglu32 -glut32
etc.
如果需要,您必须添加-lglu32 -glut32
等。