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. Linking to static library

Linking to static library

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studioquestion
5 Posts 3 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.
  • D Offline
    D Offline
    Dean Goodman
    wrote on last edited by
    #1

    I have a static library I have compiled with VS.Net -- the library compiles correctly. However, when I try to link against it I get link errors for multiply-defined symbols such as: CWPDataManager error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::operator+=(char)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@D@Z) already defined in MyDateD.lib(MyDate.obj) My library makes use of std::string (as you can see above) and I've put the approriate #ifndef include guards in the library .h file. So, why do I get these link errors when I build my app and link against my libray? Anyone know where my problem is? Thanks, --Dean

    V M 2 Replies Last reply
    0
    • D Dean Goodman

      I have a static library I have compiled with VS.Net -- the library compiles correctly. However, when I try to link against it I get link errors for multiply-defined symbols such as: CWPDataManager error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::operator+=(char)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@D@Z) already defined in MyDateD.lib(MyDate.obj) My library makes use of std::string (as you can see above) and I've put the approriate #ifndef include guards in the library .h file. So, why do I get these link errors when I build my app and link against my libray? Anyone know where my problem is? Thanks, --Dean

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Are there functions in the DLL that returns a pointer or reference to a string object? If so, one solution is to do return by value. Kuphryn

      D 1 Reply Last reply
      0
      • V valikac

        Are there functions in the DLL that returns a pointer or reference to a string object? If so, one solution is to do return by value. Kuphryn

        D Offline
        D Offline
        Dean Goodman
        wrote on last edited by
        #3

        Well, it's not a DLL - it's a static library. I have one function that takes a string by reference (consequently this is where the link errors arise from -- it's the only function that uses string). The function return is void and the string that is passed by reference is modified within the function. The function (inside the library) looks like this:

        void CMyClass::format(const char* fmt, string& dest)
        {
        ...
        (modify dest)
        ...
        }

        --Dean

        V 1 Reply Last reply
        0
        • D Dean Goodman

          Well, it's not a DLL - it's a static library. I have one function that takes a string by reference (consequently this is where the link errors arise from -- it's the only function that uses string). The function return is void and the string that is passed by reference is modified within the function. The function (inside the library) looks like this:

          void CMyClass::format(const char* fmt, string& dest)
          {
          ...
          (modify dest)
          ...
          }

          --Dean

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          Okay. See if you can pass in a const string and return the modified string instead of void. Kuphryn

          1 Reply Last reply
          0
          • D Dean Goodman

            I have a static library I have compiled with VS.Net -- the library compiles correctly. However, when I try to link against it I get link errors for multiply-defined symbols such as: CWPDataManager error LNK2005: "public: class std::basic_string,class std::allocator > & __thiscall std::basic_string,class std::allocator >::operator+=(char)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@D@Z) already defined in MyDateD.lib(MyDate.obj) My library makes use of std::string (as you can see above) and I've put the approriate #ifndef include guards in the library .h file. So, why do I get these link errors when I build my app and link against my libray? Anyone know where my problem is? Thanks, --Dean

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            That's usually caused by the build settings for the LIB using one form of CRT linking (static or DLL) and the executable using the other. --Mike-- The Internet is a place where absolutely nothing happens.   -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm

            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