Advertisement Jump to content
Sign in to follow this  

How to statically link GLEW using MinGW?

This topic is 3034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've followed GLEW's instructions as best I can, but I can't get my project to run.

I'm on Vista 32 with an nVidia Quadro NVS 140M card.
I can get an OpenGL 3.3 forward-compatibility context + core profile via GLFW.
GLEW's bundled utility progs confirm the availability of 3.3 functions on my machine.

I have included glew.c in my program, and #included <glew.h>. I have linked:
libglu32.a all the stuff GLFW requires.

The program compiles fine and glewInit() returns GLEW_OK . A blank-screen (no drawing) test confirms I can get a GL window.

BUT, when execution gets to the first OpenGL function, there's a segfault. It looks like the function pointer is null. I'm guessing GLEW isn't fetching them for me, but being as how GLEW's all preprocessor macros-on-top-of-macros, the debugger can't tell me what's (not) happening.

Is anybody else statically linking GLEW with MinGW? How did they set it up?

Share this post

Link to post
Share on other sites
Something like this:

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

int main(int argc, char** argv) {
if (!glewIsSupported("GL_VERSION_2_0")) {
fprintf(stderr, "OpenGL 2.0 not available\n");
return 1;

return 0;

Link to glew32s.lib then libopengl32.a

Share this post

Link to post
Share on other sites
BitMaster: Yes, the only thing that happens before glewInit() is the creation of a context & window by GLFW. This is the way GLEW required it.

Zeophlite: Your suggestion continues to produce the segfault. glewIsSupported() confirms I have support for GL3.3 . GLEW_STATIC is defined via Code::Block's build options and I can confirm in-code that the IDE defines it.

I've also tried compiling my own library, by importing the glew_static.dsp VC6 project into Code::Blocks. It gives me a 'libglew_static.a' file which still doesn't stop the segfault.

Thanks for your help

Share this post

Link to post
Share on other sites
The above works for NetBeans, using MinGW. Someone else with more experience on Code:Blocks will have to help you out.

Share this post

Link to post
Share on other sites
I think I've found the problem, and it's nothing to do with linking. I had to dig right into the guts of GLEW to work it out though.

As part of the process of grabbing extension pointers, GLEW checks whether the given function is actually available in a string-parsing routine. That routine uses a deprecated OpenGL function which GL 3.3 won't expose unless in the compatibility profile. Setting that profile solved my issues.

FYI, the deprecated OpenGL function is glGetString().
The problematic GLEW function is glewGetExtension() in glew.c .

I want to make sure this is a genuine oversight of GLEW's rather than something the library should normally pick up. If not I'll probably edit the function myself, as I need my OpenGL to disallow legacy functions.

Briefly, my current setup which now works with this tutorial:

- GLEW files (i.e. the source-code download) in their own folder (i.e. not pasted into the compiler's or Windows' include/lib folders)
- include search directories for project set to ..\glew\include (with -I for MinGW on the cmd line, or Project > Build Options > Search directories in Code::Blocks)
- libopengl32.a and libglu32.a linked to (with -l for MinGW cmd line, or Project > Build Options > Linker settings for Code::Blocks)
- glew.c added to the project like I would a normal code file (it's in ..\glew\src)
- #include <GL\glew.h> at the top of the main code file
- #define GLEW_STATIC somewhere before that (I did it with Code::Blocks via Project > Build Options > Compiler settings > #defines)

- I did NOT have to link to glew32.lib or any other glew lib
- I did NOT have to use the dll (hence static linking)
- I did NOT include gl.h or glu.h separately, or involve gl3.h at all

Be aware that GL 3.2 or above typically defaults to the core profile. I needed to specify the compatibility profile to get GLEW to work.

EDIT: Old bug apparently...

One possible solution is here, but I think I'll just rewrite glewGetExtension() myself to use glGetStringi().

[Edited by - MountainGod on October 4, 2010 5:52:35 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!