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. How do I use stl in a static lib?

How do I use stl in a static lib?

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiontestingbeta-testinghelp
5 Posts 3 Posters 21 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
    Lost User
    wrote on last edited by
    #1

    I'm trying to create a static lib with a simple class that has a single method that returns a std::string. I can build the static library just fine but when I link my application against the static library I get an error about multiple defines of std::basic_string. Has anyone done this successfully? Thanks, Brad ------------------------------------------------------- My header file:#if !defined( __CTest_h__ ) #define __CTest_h__ class CTest { public: CTest(); ~CTest(); std::string Try( void ); }; #endif ------------------------------------------------------ The corresponding .cpp file: #include "StdAfx.h" #include "CTest.h" CTest::CTest( void ) { } CTest::~CTest( void ) { } std::string CTest::Try( void ) { std::string strResult = "testing"; return strResult; } -------------------------------------------------------- is #included in StdAfx.h

    J U 2 Replies Last reply
    0
    • L Lost User

      I'm trying to create a static lib with a simple class that has a single method that returns a std::string. I can build the static library just fine but when I link my application against the static library I get an error about multiple defines of std::basic_string. Has anyone done this successfully? Thanks, Brad ------------------------------------------------------- My header file:#if !defined( __CTest_h__ ) #define __CTest_h__ class CTest { public: CTest(); ~CTest(); std::string Try( void ); }; #endif ------------------------------------------------------ The corresponding .cpp file: #include "StdAfx.h" #include "CTest.h" CTest::CTest( void ) { } CTest::~CTest( void ) { } std::string CTest::Try( void ) { std::string strResult = "testing"; return strResult; } -------------------------------------------------------- is #included in StdAfx.h

      J Offline
      J Offline
      Jesse Ezell
      wrote on last edited by
      #2

      For one, you aren't directly including the header file as far as I can tell...that might have something to do with it. Of course, it might just be easier to use CString instead of string (it is what MFC uses anyway and it basically offers the same functionality).
      ================== The original message was: I'm trying to create a static lib with a simple class
      that has a single method that returns a std::string. I
      can build the static library just fine but when I link
      my application against the static library I get an error
      about multiple defines of std::basic_string.

      Has anyone done this successfully?

      Thanks,
      Brad
      -------------------------------------------------------

      My header file:#if !defined( __CTest_h__ )
      #define __CTest_h__

      class CTest {
      public:
      CTest();
      ~CTest();

      std::string Try( void );
      };

      #endif

      ------------------------------------------------------
      The corresponding .cpp file:

      #include "StdAfx.h"
      #include "CTest.h"

      CTest::CTest(
      void
      ) {
      }

      CTest::~CTest(
      void
      ) {
      }

      std::string CTest::Try(
      void
      ) {
      std::string strResult = "testing";

      return strResult;
      }

      --------------------------------------------------------

      is #included in StdAfx.h

      L 2 Replies Last reply
      0
      • J Jesse Ezell

        For one, you aren't directly including the header file as far as I can tell...that might have something to do with it. Of course, it might just be easier to use CString instead of string (it is what MFC uses anyway and it basically offers the same functionality).
        ================== The original message was: I'm trying to create a static lib with a simple class
        that has a single method that returns a std::string. I
        can build the static library just fine but when I link
        my application against the static library I get an error
        about multiple defines of std::basic_string.

        Has anyone done this successfully?

        Thanks,
        Brad
        -------------------------------------------------------

        My header file:#if !defined( __CTest_h__ )
        #define __CTest_h__

        class CTest {
        public:
        CTest();
        ~CTest();

        std::string Try( void );
        };

        #endif

        ------------------------------------------------------
        The corresponding .cpp file:

        #include "StdAfx.h"
        #include "CTest.h"

        CTest::CTest(
        void
        ) {
        }

        CTest::~CTest(
        void
        ) {
        }

        std::string CTest::Try(
        void
        ) {
        std::string strResult = "testing";

        return strResult;
        }

        --------------------------------------------------------

        is #included in StdAfx.h

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

        That should read you aren't directly including the < string > header file ================== The original message was: For one, you aren't directly including the header file as far as I can tell...that might have something to do with it. Of course, it might just be easier to use CString instead of string (it is what MFC uses anyway and it basically offers the same functionality).

        ==================
        The original message was:

        I'm trying to create a static lib with a simple class
        that has a single method that returns a std::string. I
        can build the static library just fine but when I link
        my application against the static library I get an error
        about multiple defines of std::basic_string.

        Has anyone done this successfully?

        Thanks,
        Brad
        -------------------------------------------------------

        My header file:#if !defined( __CTest_h__ )
        #define __CTest_h__

        class CTest {
        public:
        CTest();
        ~CTest();

        std::string Try( void );
        };

        #endif

        ------------------------------------------------------
        The corresponding .cpp file:

        #include "StdAfx.h"
        #include "CTest.h"

        CTest::CTest(
        void
        ) {
        }

        CTest::~CTest(
        void
        ) {
        }

        std::string CTest::Try(
        void
        ) {
        std::string strResult = "testing";

        return strResult;
        }

        --------------------------------------------------------

        is #included in StdAfx.h

        1 Reply Last reply
        0
        • L Lost User

          I'm trying to create a static lib with a simple class that has a single method that returns a std::string. I can build the static library just fine but when I link my application against the static library I get an error about multiple defines of std::basic_string. Has anyone done this successfully? Thanks, Brad ------------------------------------------------------- My header file:#if !defined( __CTest_h__ ) #define __CTest_h__ class CTest { public: CTest(); ~CTest(); std::string Try( void ); }; #endif ------------------------------------------------------ The corresponding .cpp file: #include "StdAfx.h" #include "CTest.h" CTest::CTest( void ) { } CTest::~CTest( void ) { } std::string CTest::Try( void ) { std::string strResult = "testing"; return strResult; } -------------------------------------------------------- is #included in StdAfx.h

          U Offline
          U Offline
          User 1052
          wrote on last edited by
          #4

          In your stdafx.h put the following #include using namespaces std; the second line allows you to just make your declarations like so: string strmystring; string = "This is a string"; ================== The original message was: I'm trying to create a static lib with a simple class
          that has a single method that returns a std::string. I
          can build the static library just fine but when I link
          my application against the static library I get an error
          about multiple defines of std::basic_string.

          Has anyone done this successfully?

          Thanks,
          Brad
          -------------------------------------------------------

          My header file:#if !defined( __CTest_h__ )
          #define __CTest_h__

          class CTest {
          public:
          CTest();
          ~CTest();

          std::string Try( void );
          };

          #endif

          ------------------------------------------------------
          The corresponding .cpp file:

          #include "StdAfx.h"
          #include "CTest.h"

          CTest::CTest(
          void
          ) {
          }

          CTest::~CTest(
          void
          ) {
          }

          std::string CTest::Try(
          void
          ) {
          std::string strResult = "testing";

          return strResult;
          }

          --------------------------------------------------------

          is #included in StdAfx.h

          1 Reply Last reply
          0
          • J Jesse Ezell

            For one, you aren't directly including the header file as far as I can tell...that might have something to do with it. Of course, it might just be easier to use CString instead of string (it is what MFC uses anyway and it basically offers the same functionality).
            ================== The original message was: I'm trying to create a static lib with a simple class
            that has a single method that returns a std::string. I
            can build the static library just fine but when I link
            my application against the static library I get an error
            about multiple defines of std::basic_string.

            Has anyone done this successfully?

            Thanks,
            Brad
            -------------------------------------------------------

            My header file:#if !defined( __CTest_h__ )
            #define __CTest_h__

            class CTest {
            public:
            CTest();
            ~CTest();

            std::string Try( void );
            };

            #endif

            ------------------------------------------------------
            The corresponding .cpp file:

            #include "StdAfx.h"
            #include "CTest.h"

            CTest::CTest(
            void
            ) {
            }

            CTest::~CTest(
            void
            ) {
            }

            std::string CTest::Try(
            void
            ) {
            std::string strResult = "testing";

            return strResult;
            }

            --------------------------------------------------------

            is #included in StdAfx.h

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

            Sorry the '<' & '>' in my orriginal post were treated as html; < string > is #included in the stdafx.h. 1. I do not use 'using namespace std' because that I want to use the namespace and not just ignore it, therefor I scope all of the stl strings with std::. This works very well. 2. I am not using CString because I don't want to use MFC for this and because I am using string in this example when I also want to use stl vector and map classes. 3. No one has addressed my original problem which is multiple defines. The code for the static library builds just fine. I am getting the multiple defines in the application that also uses stl and links with my static library. Brad ================== The original message was: For one, you aren't directly including the header file as far as I can tell...that might have something to do with it. Of course, it might just be easier to use CString instead of string (it is what MFC uses anyway and it basically offers the same functionality).

            ==================
            The original message was:

            I'm trying to create a static lib with a simple class
            that has a single method that returns a std::string. I
            can build the static library just fine but when I link
            my application against the static library I get an error
            about multiple defines of std::basic_string.

            Has anyone done this successfully?

            Thanks,
            Brad
            -------------------------------------------------------

            My header file:#if !defined( __CTest_h__ )
            #define __CTest_h__

            class CTest {
            public:
            CTest();
            ~CTest();

            std::string Try( void );
            };

            #endif

            ------------------------------------------------------
            The corresponding .cpp file:

            #include "StdAfx.h"
            #include "CTest.h"

            CTest::CTest(
            void
            ) {
            }

            CTest::~CTest(
            void
            ) {
            }

            std::string CTest::Try(
            void
            ) {
            std::string strResult = "testing";

            return strResult;
            }

            --------------------------------------------------------

            is #included in StdAfx.h

            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