Sign in to follow this  

Help needed about multiple includes?

This topic is 3774 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 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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 declarations
typedef 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3774 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this