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. Problem linking stl strings

Problem linking stl strings

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
9 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.
  • L Offline
    L Offline
    Londo
    wrote on last edited by
    #1

    Hi, I'm having a bit of a problem linking my application using stl. I have a library that uses the stl string. This is also used in a header file used by the application that links to the library. I get a bunch of linker errors LNK4006 saying that std::basic_string is already defined in the lib. Can anyone shed any light on what I need to do to overcome this?

    P L L 3 Replies Last reply
    0
    • L Londo

      Hi, I'm having a bit of a problem linking my application using stl. I have a library that uses the stl string. This is also used in a header file used by the application that links to the library. I get a bunch of linker errors LNK4006 saying that std::basic_string is already defined in the lib. Can anyone shed any light on what I need to do to overcome this?

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      The problem is that the std:basic_string object that you have is declared twice between your lib file and your application. Is there a variable or a typedef in your project that is the same as a variable in the lib that you are using? Possibly in the header file that you mentioned. Did you write the LIB?

      L 1 Reply Last reply
      0
      • P Paul M Watt

        The problem is that the std:basic_string object that you have is declared twice between your lib file and your application. Is there a variable or a typedef in your project that is the same as a variable in the lib that you are using? Possibly in the header file that you mentioned. Did you write the LIB?

        L Offline
        L Offline
        Londo
        wrote on last edited by
        #3

        Yep, I wrote it. The class Token is declared in Token.h and is implemented in the lib, and used by the application calling the lib. class Token { std::string tokenText; public: ... bool operator==(const std::string& aTokenText); ... }; It worked ok, until I included token.h in the calling app. There are no other typedefs in the header and it has include guards.

        P 1 Reply Last reply
        0
        • L Londo

          Yep, I wrote it. The class Token is declared in Token.h and is implemented in the lib, and used by the application calling the lib. class Token { std::string tokenText; public: ... bool operator==(const std::string& aTokenText); ... }; It worked ok, until I included token.h in the calling app. There are no other typedefs in the header and it has include guards.

          P Offline
          P Offline
          Paul M Watt
          wrote on last edited by
          #4

          If you comment out the one member tokenText in your class, do you still get the error?

          L 1 Reply Last reply
          0
          • P Paul M Watt

            If you comment out the one member tokenText in your class, do you still get the error?

            L Offline
            L Offline
            Londo
            wrote on last edited by
            #5

            Yep, I still get the linking error, even after I remove all of the references to string. This is somewhat strange.

            P 1 Reply Last reply
            0
            • L Londo

              Yep, I still get the linking error, even after I remove all of the references to string. This is somewhat strange.

              P Offline
              P Offline
              Paul M Watt
              wrote on last edited by
              #6

              I would have to see the whole header file before I could help you any more, maybe you could post it, or email it to me?

              1 Reply Last reply
              0
              • L Londo

                Hi, I'm having a bit of a problem linking my application using stl. I have a library that uses the stl string. This is also used in a header file used by the application that links to the library. I get a bunch of linker errors LNK4006 saying that std::basic_string is already defined in the lib. Can anyone shed any light on what I need to do to overcome this?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I had a similar problem recently using the STL, have you tried linking your library to the DLL version of the CRT (C++ Project Options)? I can't remember why this solves the problem, but I think there's an article on MSDN (somewhere).

                1 Reply Last reply
                0
                • L Londo

                  Hi, I'm having a bit of a problem linking my application using stl. I have a library that uses the stl string. This is also used in a header file used by the application that links to the library. I get a bunch of linker errors LNK4006 saying that std::basic_string is already defined in the lib. Can anyone shed any light on what I need to do to overcome this?

                  L Offline
                  L Offline
                  Londo
                  wrote on last edited by
                  #8

                  Aaaargh... Thanks for your help guys. I had a break and came back at it with a fresh look. It turns out that the lib was being compiled with debug single threaded and... you guessed it, the app was compiled with debug multi threaded. Doh!

                  P 1 Reply Last reply
                  0
                  • L Londo

                    Aaaargh... Thanks for your help guys. I had a break and came back at it with a fresh look. It turns out that the lib was being compiled with debug single threaded and... you guessed it, the app was compiled with debug multi threaded. Doh!

                    P Offline
                    P Offline
                    Paul M Watt
                    wrote on last edited by
                    #9

                    It was still fun racking my brain.:omg:

                    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