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.
-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. -DGLEW_STATIC
is added for the same reason.-lwinmm
is added to fix the linker error: freeglut_init.c:(.text+0x5d9): undefined reference to '_timeBeginPeriod@4'
. -lgdi32
is added to fix the linker error: c:/Users/Owner/root//lib\libfreeglut_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//lib\libglew32.a(glew.o):glew.c:(.text+0x83e8): undefined reference to `_glGetString@4'
c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0xa1b2): undefined reference to `_glGetString@4'
c:/Users/Owner/root//lib\libglew32.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?
Try adding -lopengl32 last on the line to compile your program and see if it helps.
Argument order is significant with gcc
linker options.
Try this:
${G++} -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -I ${ROOTPATH}/include -L ${ROOTPATH}/lib -lopengl32 -lwinmm -lgdi32 -lglew32 -static -lfreeglut_static
Also, I don't think there's a double-dash --static
option, just -static
.
And on win32 you're going to need a successful glewInit()
before your glEnableVertexAttribArray()
function pointer will be valid. After checking your core version and/or extension, of course :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With