Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows - OpenGL + GLEW + MinGW application linking issue

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 srcmain.o ..srcmain.cpp
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o srcest.o ..srcest.cpp
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o srcwindow.o ..srcwindow.cpp
..srcwindow.cpp: In member function 'void Window::StartRenderContext()':
..srcwindow.cpp:150:24: warning: NULL used in arithmetic
..srcwindow.cpp:161:28: warning: NULL used in arithmetic
..srcwindow.cpp:174:24: warning: NULL used in arithmetic
g++ -mwindows -l glew32 -l glew32s -l glu32 -l opengl32 -o test.exe srcwindow.o srcest.o srcmain.o
srcwindow.o: In function `ZN6Window18StartRenderContextEv':
C:eclipseworkspaceestDebug/../src/window.cpp:101: undefined reference to `wglCreateContext@4'
C:eclipseworkspaceestDebug/../src/window.cpp:102: undefined reference to `wglMakeCurrent@8'
C:eclipseworkspaceestDebug/../src/window.cpp:115: undefined reference to `glewInit'
C:eclipseworkspaceestDebug/../src/window.cpp:125: undefined reference to `wglMakeCurrent@8'
C:eclipseworkspaceestDebug/../src/window.cpp:126: undefined reference to `wglDeleteContext@4'
C:eclipseworkspaceestDebug/../src/window.cpp:148: undefined reference to `__wglewChoosePixelFormatARB'
C:eclipseworkspaceestDebug/../src/window.cpp:159: undefined reference to `__wglewChoosePixelFormatARB'
C:eclipseworkspaceestDebug/../src/window.cpp:185: undefined reference to `__wglewCreateContextAttribsARB'
C:eclipseworkspaceestDebug/../src/window.cpp:194: undefined reference to `__wglewCreateContextAttribsARB'
C:eclipseworkspaceestDebug/../src/window.cpp:204: undefined reference to `__wglewCreateContextAttribsARB'
C:eclipseworkspaceestDebug/../src/window.cpp:214: undefined reference to `__wglewCreateContextAttribsARB'
C:eclipseworkspaceestDebug/../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 srcwindow.o srcest.o srcmain.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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved "glew undefined reference" problems.

My development environment is eclipse CDT with MinGW on Windows 7 (x64).

The solution is the following 3 steps:

  1. Add source code: #define GLEW_STATIC
  2. Add linker flag: -lglew32s -lopengl32 -lfreeglut
  3. Add compiling flag: gcc -DGLEW_STATIC

If needed, you have to add -lglu32 -glut32 etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...