Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static Library Problem

Status
Not open for further replies.

mainline1101

Programmer
Mar 18, 2005
2
0
0
US
I'm trying to move some code into a library, since I have multiple projects/solutions using the same code. I made the library project and it compiles into a static .lib file. Problem is when I link to it in a seperate project, I get the following errors:

Linking...
msvcprtd.lib(MSVCP71D.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?$allocator@D@2@@std@@QAE@XZ) already defined in GraphixLibraryd.lib(sdlConsole.obj)
msvcprtd.lib(MSVCP71D.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> >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in GraphixLibraryd.lib(sdlConsole.obj)
msvcprtd.lib(MSVCP71D.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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in GraphixLibraryd.lib(sdlConsole.obj)
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in GraphixLibraryd.lib(sdlConsole.obj)
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::max_size(void)const " (?max_size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in GraphixLibraryd.lib(sdlConsole.obj)
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in GraphixLibraryd.lib(sdlConsole.obj)
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::size(void)const " (?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in GraphixLibraryd.lib(sdlConsole.obj)

Now, that's really ugly, but all it's saying is the C++ string class from <string> is already defined. I don't use the string class in my library, but I do in the project I'm trying to compile. Can someone please help me out here?

J N
 
It sounds to me like you have runtime library problems here. I'm using MSVC .NET 2001, and if you right click on the main module in the solutions window and look at the properties->C++->Code Generation->Runtime Library, you have a number of choices there. The option chosen has to be the same in your application as well as your library.

Might be something to look into.
 
Thanks, you were right on. I was using the SDL library which requires projects to be compiled using DLL code generation, and I guess I had forgotten about that. I changed the options in my library to use DLL too and it worked like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top