none
error LNK2005 RRS feed

  • Question

  •  

    Hi ,

     

    Im trying to include a .cpp file. this contains a declaration and the definition of a class which I should be using.

    If I do so and try to compile there is  an error LNK2005.

     

    Iam developing the application with MFC in Visual studion 2005.

     

    Please let me know how to proceed on this.

     

    Thanks,

    Srikanth.

    Monday, November 12, 2007 5:14 AM

Answers

  • If you're including the .cpp file such as

    #include "something.cpp"

    .. there's no wonder you'll see a symbol being defined multiple times. You should extract the class into a header file, and keep any out-of-body member function definitions in the cpp file. Include the header, not the cpp, from other source files.
    Monday, November 12, 2007 10:31 AM
    Moderator

All replies

  • If you're including the .cpp file such as

    #include "something.cpp"

    .. there's no wonder you'll see a symbol being defined multiple times. You should extract the class into a header file, and keep any out-of-body member function definitions in the cpp file. Include the header, not the cpp, from other source files.
    Monday, November 12, 2007 10:31 AM
    Moderator
  •  

     Hi,

     

     Thanks, Is there any way that I can include the cpp files and manage without any errors.

     Im not allowed to modify the cpp files and create a header file for that.

     I added a flag /FORCE:MULTIPLE in the linker command line options so that it does not give any error even if it sees multiple symbols, but iam not sure its going to work. till now no problems. Am i going to have some problems ?

     

    -Srikanth.

     

     

     

     

    Monday, November 12, 2007 10:40 AM
  • Your application is simply ill-formed. Why on earth wouldn't you be allowed to make it correct? You may be able to hack and force compilations to work, but debugging will be difficult, and so will extending the application. You should confront whoever is forcing you to use the source in a specific way, rather than try to change the rules of the language.
    Monday, November 12, 2007 12:16 PM
    Moderator
  •  

     

    OK thanks,

     

    I've been doing this....

     

    thanks,

    Srikanth.

     

    Monday, November 12, 2007 12:29 PM