Advertisement Jump to content
Sign in to follow this  

One or more multiply defined symbols found??

This topic is 5257 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

Hey, I've been having a hell of a time debugging this project (C++ noob) and I've reached an error that I can not figure out. The project compiles fine but when it tries to link, it gives the following: SimpleWindowClass.obj : error LNK2005: "private: static class GameApplication * GameApplication::pApp" (?pApp@GameApplication@@0PAV1@A) already defined in GameApplication.obj Debug/GameApplication.exe : fatal error LNK1169: one or more multiply defined symbols found note**(SimpleWindowClass is the class that inherits GameApplication) I'm trying to create a class where the user can only create one instance of the object. pApp is the pointer to the class. The constructor looks like this: assert(pApp==0); pApp=this; Anyway, here's the header to the proj. I'm pretty sure the error must originate in there since its the only place that pApp is defined...

#include "windows.h"


class GameApplication  

	virtual bool AppBegin()		{ return true;}
	virtual bool AppEnd()		{ return true;}
	virtual void GetWindowDims(long& w, long& h)	{ w=640; h=480;}
	virtual LPCSTR GetTitle()	{ return "title";}
	virtual bool ProcessMessage(UINT Message, WPARAM wParam, LPARAM lParam)		{return false;}
	virtual bool KeyDown (long VirtKey, long KeyData)	{return false;}
	virtual bool KeyUp (long VirtKey, long KeyData)		{return false;}
	virtual bool Paint(WPARAM, LPARAM)	{return false;}

	static GameApplication* pApp;
	HINSTANCE appInstance;
	HWND appWindow;

	int MemberWinMain (HINSTANCE, int);
	bool InitWindow(int ShowFlag);

GameApplication* GameApplication::pApp=0;

Any help would be greatly appreciated.

Share this post

Link to post
Share on other sites
what you need are inclusion headers.
they are this:

#ifndef NAME_OF_FILE_H
#define NAME_OF_FILE_H



and that will solve the current problem you have now.

Share this post

Link to post
Share on other sites
No, include guards will not solve his problem. As a rule of thumb, include guards will never solve any linker error, only compiler errors.


I'm pretty sure the error must originate in there since its the only place that pApp is defined...

Nope, this is far from being the only place where it is defined. Whenever your header file is included in another file, that header file's contents are actually written to the including file. This means every file in your project that includes this header file will contain the line:

GameApplication* GameApplication::pApp=0;

That's quite problematic for the linker, because this variable will have been defined (and compiled) more than once: one definition per file in which the line appears.

To solve this problem, you need to do two things:
- Remove the line from a file that is included in other files (usually a .h header file)
- Put the line in a file that is compiled (usually a .cpp file), and only one.

Share this post

Link to post
Share on other sites
Thx for your help guys.

I tried the include guards but as ToohrVyk predicted, it still gave me the same error. I took

GameApplication* GameApplication::pApp=0;

out of the header file and put it into the GameApplication.cpp file. I think the reason I was getting this is because I have another class SimpleWindowClass.cpp that inherits GameApplication.cpp.

It now compiles and I'm now following a new trail of bugs :)


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!