Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help needed about multiple includes?

Started by Great_White Aug 11, 2007 at 6:51 PM 3 replies 900+ views
Original Post
Great_White
Great_White
I am developing a Framework for use with OpenGL . But I've come across a problem about header files. So far my source files are WinApp.h,WinApp.cpp, GLRenderer.h, GLRenderer.cpp. I packed all common files(windows.h, string.h, etc) into a stdafx.h header. But whenever I try to include it in some files, compiler gives the error LNK1169 (multiple defined symbols)found in XXX.obj. How can I avoid this?
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole o
dave
dave
Can you paste your stdafx.h please.
Alan Kemp
Alan Kemp
This is (probably) happening becuase you are defining variables in your header files. The header file then gets included into two seperate cpp files which when compiled each setup a variable with the same name. At linking the names conflict.

Not to get into the whole "global variables are bad thing" (don't worry, several people will be along shortly to beat that horse to death), you should be defining your variables in your cpp files, then declaring them as extern in the header so other cpp files can also use them.

"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
Great_White
Great_White
Quote:
Original post by Dave
Can you paste your stdafx.h please.


Here is the stdafx
#pragma once#ifndef _GLSTDAFX_H#define _GLSTDAFX_H// Disable pointer truncation warnings#pragma warning ( disable : 4311 ) #pragma warning ( disable : 4312 )#pragma warning ( disable : 4267 )// Disable str deprecation warnings#define _CRT_SECURE_NO_DEPRECATE// Link OpenGL Libs#pragma	comment(lib, "opengl32.lib")#pragma comment(lib, "glu32.lib")#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <GL/gl.h>#include "../GLext/glext.h"	 // GL Extensions#include "../GLext/wglext.h" // WGL Extensions#include <GL/glu.h>#include <assert.h>#include <string>#include <new>      #include <cmath>#include <ctype.h>#include <fstream>#include <crtdbg.h> // For Debugging#include <stdexcept> // Exceptions// Use 16bit Unicode character strings#include <tchar.h>typedef std::basic_string<TCHAR> w_string;#include <vector>#include <algorithm>// For Performing automatic leak checking at program exit #if defined(ENABLE_MEM_LEAK_CHCK)_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );#endif// User defined header files//---------------------------------------#include "../Math/MathFuncs.h"// Type declarationstypedef unsigned char		byte;typedef char			ch;typedef float			f32;typedef int			i32;typedef unsigned int		ui32;typedef double			d64;typedef unsigned short		us16;typedef signed short		s16; typedef signed int		si32; #if MSC_VER >= 1300	typedef __int64			i64; #else	typedef __int64			i32;#endif// Some Macros for Safe Pointer Releasing #ifndef SAFE_DELETE#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }#endif#ifndef SAFE_DELETE_ARRAY#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }#endif#endif
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole o
JohnBolton
JohnBolton
Perhaps it related to these lines. _CrtSetDbgFlag is a function. What are you trying to do here?
    #if defined(ENABLE_MEM_LEAK_CHCK)    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );    #endif 
Anyway, whenever you post a question asking why you are getting an error, you must post the error and the source of the error. Obviously, the error tells you which variables are multiply defined. It would make it a hundred times easier for us to figure out the problem if we knew which variables were involved, too.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.