God forsaken linker errors...

This is a discussion on God forsaken linker errors... within the C++ Programming forums, part of the General Programming Boards category; I keep getting a damn linker error in this header file. It seams that it works the first time it ...

  1. #1
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204

    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.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,243
    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;
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Yes, that got it... thankyou.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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