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

LNK2005

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
4 Posts 4 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.
  • J Offline
    J Offline
    jimNLX
    wrote on last edited by
    #1

    I get this error for many different symbols and it says that they are already defined in func.obj func.obj is a self contained file that does define these vars, but isn't used or call be the ones that the error is generated from. So basically I have func.cpp that defines x then I have func1.cpp and it defines x. These are local to their files why would I get this error? Thanks for the help

    R S J 3 Replies Last reply
    0
    • J jimNLX

      I get this error for many different symbols and it says that they are already defined in func.obj func.obj is a self contained file that does define these vars, but isn't used or call be the ones that the error is generated from. So basically I have func.cpp that defines x then I have func1.cpp and it defines x. These are local to their files why would I get this error? Thanks for the help

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Because they're global in scope, the linker detects the duplicate symbol "x". /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

      1 Reply Last reply
      0
      • J jimNLX

        I get this error for many different symbols and it says that they are already defined in func.obj func.obj is a self contained file that does define these vars, but isn't used or call be the ones that the error is generated from. So basically I have func.cpp that defines x then I have func1.cpp and it defines x. These are local to their files why would I get this error? Thanks for the help

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

        jimNLX wrote: These are local to their files but linker puts these files together

        1 Reply Last reply
        0
        • J jimNLX

          I get this error for many different symbols and it says that they are already defined in func.obj func.obj is a self contained file that does define these vars, but isn't used or call be the ones that the error is generated from. So basically I have func.cpp that defines x then I have func1.cpp and it defines x. These are local to their files why would I get this error? Thanks for the help

          J Offline
          J Offline
          Jonas Larsson
          wrote on last edited by
          #4

          Make them static to force internal linkage. eg: -- func.cpp -- static int x; // internal linkage, global to func.cpp only -- func1.cpp -- static int x; // internal linkage, global to func1.cpp only “Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002

          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