-
Static lib question
This is the first time I've worked with static libraries and I ran into a little problem, heres the code:
libTest.h
Code:
#ifndef __LIBTEST_H__
#define __LIBTEST_H__
#if _MSC_VER > 1000
#pragma once
#endif
#pragma warning(disable: 4996)
#include <string>
using namespace::std;
class CTest
{
public:
CTest(void);
~CTest(void);
int Test();
private:
string m_sTest;
};
#endif
libTest.cpp
Code:
#include "libTest.h"
CTest::CTest(void)
{
m_sTest = "";
}
CTest::~CTest(void)
{
}
int CTest::Test()
{
return m_sTest.size();
}
When I include/link to the libTest library on an application that already includes <string>, I get:
1>msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$alloc ator@D@2@@std@@QAE@XZ) already defined in Main.obj
How can I get rid of this problem? My library makes uses of strings/vectors/maps and so on and they all cause 'multiply defined symbol' errors.
Thanks in advance for any help.
-
Anyone have any idea?
I've been looking through example static library sources, but none of them seem to use the stl library.
-
Make sure your lib and your project that uses the lib match in their runtime library linkage. (Under project settings, C/C++ -> Code Generation -> Runtime Library )