Thread: Static lib question

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    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.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    Anyone have any idea?
    I've been looking through example static library sources, but none of them seem to use the stl library.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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 )
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. problem about static Lib and function pointer
    By wu7up in forum C Programming
    Replies: 3
    Last Post: 02-24-2003, 09:34 AM
  5. question about static members
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2003, 10:21 AM