I have a solution with three projects (library, thesis, and main). The
main project has a configuration type of "Application (.exe)", and the
other two are "static library (.lib)". The dependences are as follows
- main depends on both thesis and library
- thesis depends on library
- library does not depend on any other projects, but does use some
third-party libs
When I I build the solution, I get a bunch of "error LNK2005" at link
time. The symbols it complains about are all STL stuff, like in
std::basic_string, std::basic_ostream, std::basic_streambuf, etc.
I rebuilt all the projects, so it's not an inconsistency thing. I
googled around and saw that this can happen when different projects
are linking in different versions of the standard runtime libraries. I
checked the project settings for each, and they are all set to use
"Multithreaded DLL (/MD)". However, I worry that it could be that some
of the third-party libs have the same symbols linked in, and in a
different mode (e.g. single-threaded) than I am using. If that's the
case, how might I get this to work?
Also, I'm using VC++ 2008 Express, which apparently does not have
single-threaded mode. This is not good for my purposes, because I
really need fast code and am not doing any multithreading. So, I don't
want the overhead of the multithread libs.
I've included the linking errors below, for the curious. Any help is
much appreciated.
Thanks.
Dave
2>msvcprt.lib(MSVCP90.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 thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::operator<<(int)" (??6?$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEAAV01@H@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::operator<<(class std::basic_ostream<char,struct
std::char_traits<char> > & (__cdecl*)(class
std::basic_ostream<char,struct std::char_traits<char> > &))" (??6?
$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z) already
defined in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::operator<<(double)" (??6?$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEAAV01@N@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "class
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
std::endl(class std::basic_ostream<char,struct std::char_traits<char>
> &)" (?endl@std@@YAAAV?$basic_ostream@DU?
$char_traits@D@std@@@1@AAV21@@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::operator<<(unsigned int)" (??6?$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEAAV01@I@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.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
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::operator<<(bool)" (??6?$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEAAV01@_N@Z) already defined in
thesis.lib(numerical_integrator.obj)
2>msvcprt.lib(MSVCP90.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 thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall
std::basic_ios<char,struct std::char_traits<char>
>::setstate(int,bool)" (?setstate@?$basic_ios@DU?
$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall
std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already
defined in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall
std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char
const *,int)" (?sputn@?$basic_streambuf@DU?
$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static bool
__cdecl std::char_traits<char>::eq_int_type(int const &,int const
&)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static int
__cdecl std::char_traits<char>::eof(void)" (?eof@?
$char_traits@D@std@@SAHXZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall
std::basic_streambuf<char,struct std::char_traits<char>
>::sputc(char)" (?sputc@?$basic_streambuf@DU?
$char_traits@D@std@@@std@@QAEHD@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall
std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const
" (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?
$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: char __thiscall
std::basic_ios<char,struct std::char_traits<char> >::fill(void)const
" (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already
defined in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall
std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ)
already defined in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: int __thiscall
std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ)
already defined in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static unsigned
int __cdecl std::char_traits<char>::length(char const *)" (?length@?
$char_traits@D@std@@SAIPBD@Z) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::flush(void)" (?flush@?$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
std::basic_ostream<char,struct std::char_traits<char> > * __thiscall
std::basic_ios<char,struct std::char_traits<char> >::tie(void)const
" (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?
$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: bool __thiscall
std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already
defined in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall
std::basic_ostream<char,struct std::char_traits<char>
>::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?
$char_traits@D@std@@@std@@QAEXXZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall
std::basic_streambuf<char,struct std::char_traits<char>
>::_Lock(void)" (?_Lock@?$basic_streambuf@DU?
$char_traits@D@std@@@std@@QAEXXZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall
std::basic_streambuf<char,struct std::char_traits<char>
>::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?
$char_traits@D@std@@@std@@QAEXXZ) already defined in
thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall
std::_Mutex::_Lock(void)" (?_Lock@_Mutex@std@@QAEXXZ) already defined
in thesis.lib(jellyfish_slice_controller.obj)
2>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: void __thiscall
std::_Mutex::_Unlock(void)" (?_Unlock@_Mutex@std@@QAEXXZ) already
defined in thesis.lib(jellyfish_slice_controller.obj)
You can also check this page in the "to fix try checking..." section:
http://msdn.microsoft.com/en-us/library/72zdcz6f(VS.80).aspx
Alright, so what might I be able to do about this? With VC 2008
Express, I can't use single-threaded libs.
Hmm, the first link doesn't seem to be up to date for VC 2008 Express.
"Solution one" mentions the "Object/library modules" box, which
doesn't exist in 2008E, or have any obvious corresponding setting. If
I simply add msvcprt.lib to the ignore list, I get
LINK : fatal error LNK1104: cannot open file 'libcp.lib'
For solution two, I can't figure out how to get verbose library
listing.
This did get me thinking that it might have something to do with MFC,
though I am not sure what. I tried setting all projects to "use the
MFC in a shared library", but no go.
Oh, and I just tried stripping my code down so that it does not use
the third-party libs, to see if it would link (though much of the
functionality is commended out). Same errors.