LNK2005 error: class redifinition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabil035
    New Member
    • Mar 2008
    • 34

    LNK2005 error: class redifinition

    I have COM server written in VC++ 6

    And I'm migrating this aplication to VS2005, i've reach a good level in my project but now I have this famous erros LNK2005.

    I know the cause :( #include) calls the same file 2 times

    but I should let the code without changes cuz it's not mine

    so if you can give me an idea to resolve this problem just by modifying project properties or by adding some macros in header files
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You need inclusion guards in your header files. If you don't have them, then you will get redefinition errors.

    [code=c]
    #ifndef ASYMBOL
    #define ASYMBOL

    Header file contents...

    #endif
    [/code]

    I am sure you have seen these before.

    Comment

    • nabil035
      New Member
      • Mar 2008
      • 34

      #3
      thx but it's not the problem

      I explain u more

      in my header file I have implementation of function

      I include this file twice in 2 cpp files

      so I will have after the compilation two references of this method in 2 different .obj


      if I seprate implementation and declaration all things are ok but I have not the possibility of changing code

      Comment

      • nabil035
        New Member
        • Mar 2008
        • 34

        #4
        in the header file, we should add the key word inline to the functions that are implemented in the header.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by nabil035
          in my header file I have implementation of function
          Don't do this.

          Your function implementation belongs in a source file. That way there is one definition.

          The header file as the function prototype.

          You include the header in each source file.

          Your build compiles using multiple source files.

          The inline qualifier is an optimization not a work-around. By using it each time you call the function, the call is replaced by a complete copy of the function definition. Call the function in 500 places and your executable has 500 copies of the function definition. Now you have a really bloated executable.

          Comment

          Working...