Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. LNK2005 Error

LNK2005 Error

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shajeel
    wrote on last edited by
    #1

    Hi I have a dll application, which was compiling/linking fine and working correctly. I have to add a function to say class B.cpp/B.h which is similar to another function in another class say A.cpp/A.h. So I copied the function from A and made changes and added it to B. When i compiled it, there was a undeclared identifier error on a function. I checked where the function was defined and added #include xyz.h on the top of the B.cpp. When i compiled it now, it gave me lots of LNK2005 error with message "already defined in B.obj". I worked mostly in C#, so have on idea of this linking issue. Most of the google searches ask me to change project settings, which is not solving the problem.

    Regards Shajeel

    S M 2 Replies Last reply
    0
    • S Shajeel

      Hi I have a dll application, which was compiling/linking fine and working correctly. I have to add a function to say class B.cpp/B.h which is similar to another function in another class say A.cpp/A.h. So I copied the function from A and made changes and added it to B. When i compiled it, there was a undeclared identifier error on a function. I checked where the function was defined and added #include xyz.h on the top of the B.cpp. When i compiled it now, it gave me lots of LNK2005 error with message "already defined in B.obj". I worked mostly in C#, so have on idea of this linking issue. Most of the google searches ask me to change project settings, which is not solving the problem.

      Regards Shajeel

      S Offline
      S Offline
      shivditya
      wrote on last edited by
      #2

      Its very simple. Project - > settings Go to linker tab. In linker tab project options edit box at end , just add -------> /FORCE:MULTIPLE Press ok. I hope your problem will be solved.

      || ART OF LIVING ||

      S P 2 Replies Last reply
      0
      • S shivditya

        Its very simple. Project - > settings Go to linker tab. In linker tab project options edit box at end , just add -------> /FORCE:MULTIPLE Press ok. I hope your problem will be solved.

        || ART OF LIVING ||

        S Offline
        S Offline
        Shajeel
        wrote on last edited by
        #3

        I am using VS 2002, can you tell me settings for that as i don't have any Project -> settings options here.

        Regards Shajeel

        S 1 Reply Last reply
        0
        • S Shajeel

          I am using VS 2002, can you tell me settings for that as i don't have any Project -> settings options here.

          Regards Shajeel

          S Offline
          S Offline
          shivditya
          wrote on last edited by
          #4

          I am sorry I am using vc 6.0 only.

          || ART OF LIVING ||

          1 Reply Last reply
          0
          • S shivditya

            Its very simple. Project - > settings Go to linker tab. In linker tab project options edit box at end , just add -------> /FORCE:MULTIPLE Press ok. I hope your problem will be solved.

            || ART OF LIVING ||

            P Offline
            P Offline
            prithaa
            wrote on last edited by
            #5

            Hello, I have a question in the same regard. Just now I tried what you suggested /FORCE:MULTIPLE since I was getting Linker error saying 'already defined'. Now because the settings are changed I get warnings saying that the 'x identifier already defined in MainFrm.obj; second definition ignored' So should I stick on to these new settings because even I tried all of the following for my identifier consts file #pragma once #ifndef #define #endif But none of the above worked.With your suggestion the errors are transferred to warnings. What exactly this /FORCE:MULTIPLE do? Thanks Prithaa

            S D 2 Replies Last reply
            0
            • P prithaa

              Hello, I have a question in the same regard. Just now I tried what you suggested /FORCE:MULTIPLE since I was getting Linker error saying 'already defined'. Now because the settings are changed I get warnings saying that the 'x identifier already defined in MainFrm.obj; second definition ignored' So should I stick on to these new settings because even I tried all of the following for my identifier consts file #pragma once #ifndef #define #endif But none of the above worked.With your suggestion the errors are transferred to warnings. What exactly this /FORCE:MULTIPLE do? Thanks Prithaa

              S Offline
              S Offline
              shivditya
              wrote on last edited by
              #6

              Force multiple just ignores second definition with same name. It is generally risky for very big projects in VC++. But I never found it that risky.

              || ART OF LIVING ||

              P 1 Reply Last reply
              0
              • S shivditya

                Force multiple just ignores second definition with same name. It is generally risky for very big projects in VC++. But I never found it that risky.

                || ART OF LIVING ||

                P Offline
                P Offline
                prithaa
                wrote on last edited by
                #7

                Hello, Thanks, For now my problem is solved.I'll keep this in mind. Bye Prithaa

                1 Reply Last reply
                0
                • P prithaa

                  Hello, I have a question in the same regard. Just now I tried what you suggested /FORCE:MULTIPLE since I was getting Linker error saying 'already defined'. Now because the settings are changed I get warnings saying that the 'x identifier already defined in MainFrm.obj; second definition ignored' So should I stick on to these new settings because even I tried all of the following for my identifier consts file #pragma once #ifndef #define #endif But none of the above worked.With your suggestion the errors are transferred to warnings. What exactly this /FORCE:MULTIPLE do? Thanks Prithaa

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  prithaa wrote:

                  What exactly this /FORCE:MULTIPLE do?

                  See here.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  1 Reply Last reply
                  0
                  • S Shajeel

                    Hi I have a dll application, which was compiling/linking fine and working correctly. I have to add a function to say class B.cpp/B.h which is similar to another function in another class say A.cpp/A.h. So I copied the function from A and made changes and added it to B. When i compiled it, there was a undeclared identifier error on a function. I checked where the function was defined and added #include xyz.h on the top of the B.cpp. When i compiled it now, it gave me lots of LNK2005 error with message "already defined in B.obj". I worked mostly in C#, so have on idea of this linking issue. Most of the google searches ask me to change project settings, which is not solving the problem.

                    Regards Shajeel

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    /FORCE:MULTIPLE? :wtf: Just adding a function to another class shouldn't give new linker errors, unless you never define the function.  Did you copy the function and not change the scope resolution stuff? With namespaces and classes (C++!) there shouldn't ever be multiple definitions. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    P 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      /FORCE:MULTIPLE? :wtf: Just adding a function to another class shouldn't give new linker errors, unless you never define the function.  Did you copy the function and not change the scope resolution stuff? With namespaces and classes (C++!) there shouldn't ever be multiple definitions. Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      P Offline
                      P Offline
                      prithaa
                      wrote on last edited by
                      #10

                      Hello, Because of this FORCE:MULTIPLE my linker errors "already defined in another class' have become warnings so is that fine? I had tried using #pragma once #ifndef #define #endif but none of them worked Thanks Prithaa

                      M 1 Reply Last reply
                      0
                      • P prithaa

                        Hello, Because of this FORCE:MULTIPLE my linker errors "already defined in another class' have become warnings so is that fine? I had tried using #pragma once #ifndef #define #endif but none of them worked Thanks Prithaa

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #11

                        I'm just suspicious - What is defined twice in two different classes ?  Is this really what you want? Hiding it with a linker option may not be the best solution :) Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups