C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2009, 05:55 PM   #1
Not stupid, just stupider
 
yaya's Avatar
 
Join Date: May 2007
Location: Earthland
Posts: 191
Thumbs up God forsaken linker errors...

I keep getting a damn linker error in this header file. It seams that it works the first time it is processed but every time I call it again, it pops up with another (of the same) error. Here's the code:

Code:
#ifndef MESSAGE_H_
#define MESSAGE_H_

#include "globaltypes.h"

// MESSAGE LIST
enum MSG
{
	MSG_NONE = 0, // default
	MSG_FAIL = 0, //
	MSG_SUCCESS = 1, //
	MSG_OK = 1, //
	
	MSG_ERROR, // string of error message
	MSG_WARNING, // string of warning message

	MSG_TOTALMESSAGETYPES
};

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

	bool Dispatch( MSG Type, void *Data = NULL );
	bool DispatchOne( MSG Type, void *Data, UINT16 Number );
	bool DispatchThis( MSG Type, void *Data = NULL );
	virtual bool Device( const MSG Type, const void *Data );

private:
	UINT16 NumberID;
};

class MESSAGE_TOP
{
public:
	UINT16 Add( MESSAGE* pDevice );
	bool Dispatch( MSG Type, void *Data = NULL );
	bool DispatchOne( MSG Type, void *Data, UINT16 Number );
	MESSAGE* Get( const UINT16 Number ) const;
	UINT16 Remove( const UINT16 Number );
	void RemoveAll();
	UINT16 Size() const;

private:
	std::vector< MESSAGE* > Device;
} extern Message; // THIS IS CAUSING PROBLEMS HERE!!!

#endif
The error is on the line towards the end (extern Message). This is the linker error:

Code:
error LNK2001: unresolved external symbol "class MESSAGE_TOP Message" (?Message@@3VMESSAGE_TOP@@A)
And this is the error without the extern in there:

Code:
error LNK2005: "class MESSAGE_TOP Message" (?Message@@3VMESSAGE_TOP@@A) already defined
I've tried all sorts of things but I give up. This is apart of my global header, so it is known to pretty much every other part of the program.

Thanks.
yaya is offline   Reply With Quote
Old 12-14-2009, 06:17 PM   #2
Staff software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 6,014
Do you actually declare "MESSAGE Message;" in any .cpp file anywhere? An extern on its own is not enough. The extern just tells the rest of the code to expect that symbol to be present at link-time, but doesn't create the symbol.

Also, I'd recommend separating out the extern declaration from the class declaration:

Code:
class MESSAGE
{
    ...
};

extern MESSAGE Message;
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 12-14-2009, 06:26 PM   #3
Not stupid, just stupider
 
yaya's Avatar
 
Join Date: May 2007
Location: Earthland
Posts: 191
Yes, that got it... thankyou.
yaya is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linker Errors in OpenGL Sentral Game Programming 2 07-19-2005 04:29 PM
Linker errors - Multiple Source files nkhambal C Programming 3 04-24-2005 02:41 AM
help, linker errors when adding library file to project ngcfan525 C++ Programming 1 03-09-2003 02:27 PM
Linker errors with simple static library Dang Windows Programming 5 09-08-2001 09:38 AM


All times are GMT -6. The time now is 12:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22