View Full Version : wglext.h compile problem

04-04-2011, 12:07 PM
Hey all,

I am having a really annoying problem while trying to use wglChoosePixelFormatARB in order to achieve multisampling in windows.

I need to include "wglext.h" in order to point the function pointer to its declaration. I have already included "glext.h" for many function pointers successfully in my project in the past, so I would guess that the way to do it is the same. This is how I do it.

#include <GL/gl.h>
#include <GL/glu.h>
#include "wglext.h" //including wgl extensions
#include "glext.h" //including gl extension

(I also tried including glext.h before wglext.h)

It's pretty standard, but despite that I am getting building errors that seem to indicate that wglext.h does not see windows.h
Errors like:

error: 'DWORD' does not name a type|
error: 'CHAR' does not name a type|
error: 'CHAR' does not name a type|
error: typedef 'BOOL' is initialized (use decltype instead)|
error: expected primary-expression before '__attribute__'|
error: typedef 'PFNWGLGETEXTENSIONSSTRINGARBPROC' is initialized (use decltype instead)|
|error: 'HDC' was not declared in this scope|
error: ISO C++ forbids declaration of 'BOOL' with no type|

Even though in the start of wglext.h , just like glext.h windows.h is included. I am really not sure what is wrong here. Anyone ever had a problem of including "wglext.h"?

04-04-2011, 12:43 PM
Could it be a C versus C++ problem ?

04-04-2011, 12:53 PM
My compiler is gcc/g++. I did not think of that but since both headers start with exactly the same #ifndef macro I dont see why one would work while the other does not.

#ifdef __cplusplus
extern "C" {

04-04-2011, 05:09 PM
Try including <windows.h> before any of the GL headers.

On the other hand, I wonder why you are using gcc on a Windows machine. Do you develop on Windows at all? If not, it makes no sense in first place to include wglext.h

04-04-2011, 09:17 PM
Yes I do develop in both win32 and linux and I am using gcc in both for compatibility's sake since I am striving to be multi-platform.

I could use MSVC compiler in windows and gcc in linux but I am so used to gcc that I don't try that.

Including <windows.h> myself before any of the GL headers was one of the first things I did but it did not work.

I know this is not an openGL related problem per se, but I just can't seem to find it. And the annoying thing is that no matter how much I google it none seems to be having a similar problem. Which most probably means that I am doing something very wrong somewhere that is not so obvious.

Even a simple program such as this:

#include <GL/gl.h>
#include <GL/glu.h>
#include "wglext.h" //including wgl extensions
#include "glext.h" //including gl extension

int main()

return 0;

does not compile and throws the exact same build errors. If I comment wglext.h it compiles great which just reassures that there is no problem with glext.h

I guess that means there is no problem in the way I include and build it in my main program. Not even a dummy program can compile it correctly.

Yet another edit. In the dummy program if I add #include <windows.h> before wglext.h then it does indeed compile. Hmmm ... I must be getting close. That does not happen in my main program even if I add it. That could mean what? That somehow due to some #defines in windows.h inclusion from many places cancels stuff out?

04-05-2011, 05:00 AM
I just wanted to inform that I solved the problem. It was indeed a problem of the way I compiled my project. It is quite a complicated project and with big include chains. And the error was generated because I included the chain which lead to the glext.h and wglext.h inclusion last. By placing it before all others inclusions it compiles correctly.

What I don't like is the fact that even though I did fix it I do not know the reason why it works now and it did not work before. To exhibit what I mean imagine this include hierarchy in the main file of a project. The foo_graphics include chain lead up to glext.h and wglext.h

#include "foo_setup.h"

#include "foo_graphics.h" //will compile correctly

#include "foo_signals.h" //somewhere in this chain <windows.h> gets included
#include "foo_utils.h" //somewhere in this chain <windows.h> gets included

That way it will work. But if I put the chain which leads to glext.g and wglext.h after any file that includes <windows.h> I get these errors.

#include "foo_setup.h"

#include "foo_signals.h" //somewhere in this chain <windows.h> gets included
#include "foo_utils.h" //somewhere in this chain <windows.h> gets included

#include "foo_graphics.h" //Will throw errors