Public Group

# 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.

## 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:
libopengl32.a
libglu32.a
...plus 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 on other sites
Have you called glewInit() before accessing any functions provided by GLEW?

##### Share on other sites
Something like this:

[SOURCE]#include <stdlib.h>#define GLEW_STATIC#include <GL/glew.h>int main(int argc, char** argv) {    glewInit();    if (!glewIsSupported("GL_VERSION_2_0")) {        fprintf(stderr, "OpenGL 2.0 not available\n");        return 1;    }    return 0;}[/SOURCE]

##### 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.

##### 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 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...
https://sourceforge.net/tracker/index.php?func=detail&aid=2927731&group_id=67586&atid=523274
http://www.geeks3d.com/20100721/glew-does-not-work-with-an-opengl-3-or-4-core-profile/

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]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634150
• Total Posts
3015828
×