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