Sign in to follow this  

Help needed about multiple includes?

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

// Link OpenGL Libs
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

#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

// 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;
typedef __int64 i32;

// Some Macros for Safe Pointer Releasing
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }

#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }


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?

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

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