Sign in to follow this  
Elspin

Need help with non-sensical linker errors.

Recommended Posts

So I've got some nice and fancy linker errors here that popup whenever I try and include iostream, or fstream.
1>libcmt.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invoke_watson@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invalid_parameter@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
1>libcmt.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in LIBCMTD.lib(invarg.obj)
1>libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>..\..\..\..\..\Desktop\LuaGDK\luaD_GDK.exe : fatal error LNK1169: one or more multiply defined symbols found
but I don't know how to solve them. It says to use nodefaultlib, but if I remove that default library it causes these errors:
1>WinMain.obj : error LNK2019: unresolved external symbol "void * __cdecl operator new[](unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??_U@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) referenced in function "public: char * __cdecl std::_DebugHeapAllocator<char>::allocate(unsigned int,void const *)" (?allocate@?$_DebugHeapAllocator@D@std@@QAAPADIPBX@Z)
1>WinMain.obj : error LNK2019: unresolved external symbol "struct std::_DebugHeapTag_t const & __cdecl std::_DebugHeapTag_func(void)" (?_DebugHeapTag_func@std@@YAABU_DebugHeapTag_t@1@XZ) referenced in function "public: char * __cdecl std::_DebugHeapAllocator<char>::allocate(unsigned int,void const *)" (?allocate@?$_DebugHeapAllocator@D@std@@QAAPADIPBX@Z)
1>WinMain.obj : error LNK2019: unresolved external symbol "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) referenced in function "public: void __thiscall std::_Iterator_base::_Orphan_me(void)" (?_Orphan_me@_Iterator_base@std@@QAEXXZ)
1>WinMain.obj : error LNK2019: unresolved external symbol "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) referenced in function "protected: void __thiscall std::ios_base::_Init(void)" (?_Init@ios_base@std@@IAEXXZ)
1>WinMain.obj : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >::operator*(void)const " (??D?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEABDXZ)
1>..\..\..\..\..\Desktop\LuaGDK\luaD_GDK.exe : fatal error LNK1120: 5 unresolved externals

Share this post


Link to post
Share on other sites
Chances are this is because you're using a library that is linked against a different version of the runtime then your project is setup to use. The nodefaultlib recommendation of the compiler is usually a "bad thing(tm)" to do, as it doesn't usually solve the problem, and just attempts to avoid it.

For instance, your project might be set to compile using "multi-threaded DLL" (or multithreaded debug dll) or multitheaded static. However, the library you're using was set to use something else.

In this case, it looks like your project was set to "release" and the library you're linking against was set to "debug" (or vice versa possibly, depending on how your solution is setup to build).

Basically, if you're in release mode, all the libraries must be set to release, and if your project is in debug, then the libraries must be debug libs also (there are some exceptions here, but I'm ignoring them for ease of explanation) They also have to be the same in threaded-ness (single thread vs multithread), and statically linked versus dynamically linked.

Most libraries I've used come with the option to compile a variety of ways to suit your project so you can find the right .lib to link against.

--Rhalin

Share this post


Link to post
Share on other sites
Quote:
Original post by Rhalin
Chances are this is because you're using a library that is linked against a different version of the runtime then your project is setup to use. The nodefaultlib recommendation of the compiler is usually a "bad thing(tm)" to do, as it doesn't usually solve the problem, and just attempts to avoid it.

For instance, your project might be set to compile using "multi-threaded DLL" (or multithreaded debug dll) or multitheaded static. However, the library you're using was set to use something else.

In this case, it looks like your project was set to "release" and the library you're linking against was set to "debug" (or vice versa possibly, depending on how your solution is setup to build).

Basically, if you're in release mode, all the libraries must be set to release, and if your project is in debug, then the libraries must be debug libs also (there are some exceptions here, but I'm ignoring them for ease of explanation) They also have to be the same in threaded-ness (single thread vs multithread), and statically linked versus dynamically linked.

Most libraries I've used come with the option to compile a variety of ways to suit your project so you can find the right .lib to link against.

--Rhalin


Wow, that was exactly it. I switched to release and all of a sudden, no errors :o. Thanks a lot! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this