Thread: having a linking problem

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743

    Wink having a linking problem

    I am having a problem linking that I can't seem to resolve....

    There are 3 source files:

    main.cpp, map.cpp, terrain.cpp

    There are 3 header files:

    map.h, terrain.h, vectordtp.h

    terrain.h looks like:

    Code:
    #ifndef __TERRAIN_DTP_H
    
    #define __TERRAIN_DTP_H
    
    //Includes
    #include "SDL.h"
    
    ...some constants defined....
    
    class TERRAIN_MANAGER_DTP
    {
    friend class TERRAIN_DTP;
    
    ...class declaration...
    } DefaultTileManager;
    
    class TERRAIN_DTP
    {
    ....class declaration
    };
    
    #endif
    terrain.cpp includes terrain.h and defines all functions in from the classes.

    map.h looks like such:

    Code:
    #ifndef __MAP_DTP_H
    
    #define __MAP_DTP_H
    
    #include "terrain.h"
    #include "vectordtp.h"
    
    /*********************
    MAP_DTP class
    *********************/
    
    class MAP_DTP
    {
    ...class declaration...
    };
    
    #endif
    map.cpp includes map.h and defines all functions from the class.

    vectordtp.h is a simple header file that defines my own vector and matrix classes....with both the declaration and definitions in the same file (the function definitions are encapsulated inside the class declaration).

    main.cpp looks like such:

    Code:
    #ifdef WIN32
    #pragma comment(lib, "SDL.lib")
    #pragma comment(lib, "SDLmain.lib")
    #endif
    
    //Includes
    
    #include "SDL.h"
    //#include "terrain.h"
    //#include "map.h"
    
    //Color masks
    
    bool MessageLoop ( SDL_Event &event );
    
    
    int main(int argc, char **argv)
    {
    ...code....
    }
    This is the error I am receiving:

    terrain.obj : error LNK2005: "class TERRAIN_MANAGER_DTP DefaultTileManager" (?DefaultTileManager@@3VTERRAIN_MANAGER_DTP@@A) already defined in map.obj

    I have tried moving around some include statements and such...but I can't seem to resolve this linking problem. Any ideas?
    Last edited by DavidP; 11-11-2006 at 01:25 PM.
    My Website

    "Circular logic is good because it is."

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    oops I just solved it! sorry now this post is just wasting space...

    i moved the DefaultTileManager to my terrain.cpp and then created an extern call to it in map.cpp
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with linking files
    By slippy in forum C Programming
    Replies: 2
    Last Post: 11-23-2007, 11:35 PM
  2. Linking problem
    By Agent89 in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2005, 03:03 PM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. Long file linking problem
    By hypertension in forum C Programming
    Replies: 3
    Last Post: 10-15-2002, 09:55 PM
  5. Linking problem...
    By BrianK in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2002, 04:13 PM