Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c++ - Compiling Simple static OpenGL 4.0 program using MinGW, freeglut and glew

The problem is in the title, I'll try to list what I've already tried and so on below.

First off, in my understanding, in order to use OpenGL 4.0 on windows you must extend and or bypass the default windows library as it only ships OpenGL 1.1.

So we have MinGW installed at C:/MinGW/. Next I setup FreeGLUT by downloading the tarball from the project site. Extract and compile by running the makefiles according to the instructions with a minor addition of --prefix to the ./configure command.

./configure --prefix=/c/Users/Owner/root/
make all
make install 

Now I have freeglut in /c/Users/Owner/root/lib/, /c/Users/Owner/root/include/ and so on. Next up is GLEW, my problem child as far as I can tell.

Download the source archive from the project site (direct 1.7.0.zip link). Compiling is a tad more complicated, my current recipe is derived from the stack overflow question " Building glew on windows with mingw ". An abbreviated form is listed below:

mkdir lib/
mkdir bin/
gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
ar cr lib/libglew32.a src/glew.o
gcc -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32mx.dll -Wl,--out-implib,lib/libglew32mx.dll.a -o lib/glew32mx.dll src/glew.mx.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
ar cr lib/libglew32mx.a src/glew.mx.o

and should be run from the "root" of /path/to/glew-1.7.0/.


Now with setup of libraries "done" (assuming no mistakes... ) compiling my simple program is done with this line.

${G++}  -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -lfreeglut_static -lopengl32 -lwinmm -lgdi32 -lglew32  -I ${ROOTPATH}/include -L ${ROOTPATH}/lib --static

Now to decompose this a bit and walk through why I have various "extra" arguments and to show you what errors and problems I've already run into and solved.

  1. -DFREEGLUT_STATIC and -lfreeglut_static are used instead of the normal -lfreeglut as we want a static build here. Failure to do this gives linker errors relating to freeglut.
  2. -DGLEW_STATIC is added for the same reason.
  3. -lwinmm is added to fix the linker error: freeglut_init.c:(.text+0x5d9): undefined reference to '_timeBeginPeriod@4'.
  4. -lgdi32 is added to fix the linker error: c:/Users/Owner/root//liblibfreeglut_static.a(freeglut_init.o):freeglut_init.c:(.text+0x58c): undefined reference to '_GetDeviceCaps@8'

Now I'm stumped with the following linker error:

c:/Users/Owner/root//liblibglew32.a(glew.o):glew.c:(.text+0x83e8): undefined reference to `_glGetString@4'
c:/Users/Owner/root//liblibglew32.a(glew.o):glew.c:(.text+0xa1b2): undefined reference to `_glGetString@4'
c:/Users/Owner/root//liblibglew32.a(glew.o):glew.c:(.text+0xa290): undefined reference to `_glGetString@4'

The minimal test case that produces this error (main.cpp) is.

#include <GL/glew.h>
#include <GL/freeglut.h>

int main(int argc, char **argv) {
  glEnableVertexAttribArray(0);
}

Ideas?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Try adding -lopengl32 last on the line to compile your program and see if it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...