# C++ include confusion with OpenGL

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

## Recommended Posts

Hello Guys I started reading "Beginning OpenGL" and wanted to start with a 3D Tetris. I have a basic class which is managing the pixelformat, the rendering context and so on. Here is the header
#ifndef CGLBASE_EXT_INCLUDED
#define CGLBASE_EXT_INCLUDED
#include <math.h>
#include <windows.h>
#include "TetraField.h" //this class should create the tetris field
#include <gl/gl.h>
#include <gl/glu.h>

class CGLBase
{
public:
CGLBase();
~CGLBase();

virtual bool InitGLWnd(HWND hWnd);
virtual bool ReleaseGLWnd();
virtual bool ResizeGLWnd(UINT wndWith, UINT wndHeight);
virtual bool update();
virtual bool render();

HGLRC GetRC();	//return render context
protected:
bool SetupPixelFormat(HDC hDC);
private:
HGLRC hRC;	//render context
HDC hDC;	//device context
HWND hWnd;	//handle of the current window
int PixelFormat;
TetraField *curField;
};
#endif
Then I want to have a class that is drawing every box and the field on the screen. I understand why it ends in a redeclaration error when i simply include the gl library in both classes. But I don't understand the solution of the book, to include the gl library in the .cpp file, and why it doesn't work for me with the visual studio 08 compiler. So long.

##### Share on other sites
note: I don't have that book to look at... so sorry if I'm a little off track.

What exactly is the "multiple defined symbol" error you get. It is kinda important to diagnosing the problem.

You mention "the gl library" but I just copy paste my headers as a test:
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/gl.h>
#include <gl/glu.h>

works just fine on my vs2008 So i know you aren't talking about the gl headers themselves. You must be setting something else up incorrectly, but again, the exact error (and maybe the listing of other includes from main.cpp) would be nice.

and you can enclose posted code in [source][/source] tags to keep it short and readable.

##### Share on other sites
I understand what you mean, and it's generally a bad idea to put includes in header files (you shouldn't unless you have to).
A better idea is to include all the ones you need from the C++ source files.

Like so:
CglBase.cpp:#include <math.h>#include <windows.h>#include <gl/gl.h>#include <gl/glu.h>	#include "TetraField.h" //this class should create the tetris field#include "CglBase.h" //this class should create the tetris field<Code>

##### Share on other sites
I don't get one error, I get about 150 errors all in "gl.h". Some say, this 'APENTRY' is a redefinition, some other syntax error that don't exist :D.

I can post the whole code if it helps.

These are the only two files I include in the main.cpp
#include <windows.h>#include "CGLBase.h"

##### Share on other sites
Hi!
Watch for header file order in the begining of the cpp, use google.

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

I use the nehe tutorial first prg, to see what can be compiled, then add code to this good prg.

Füge

##### Share on other sites
i know the nehe tutorial, but it's fairly not object oriented, so I tried this one. Thanks for the info, but that wasn't the problem.