What's new

ucontrollable linker errors

mesman00

What's that...?
i'm working on this project and i am getting an insane amount of linker errors, which i can't seem to find the source of. i don't know if there is something in the setting which i need to configure, etc. here are the errors i am recieving:

Code:
--------------------Configuration: dcmsrview32 - Win32 Debug--------------------
Compiling...
dcmsrview32.cpp
Linking...
libcpmtd.lib(locale0.obj) : error LNK2005: "public: class std::locale::facet const * __thiscall std::locale::_Getfacet(unsigned int,bool)const " (?_Getfacet@locale@std@@QBEPBVfacet@12@I_N@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale0.obj) : error LNK2005: "public: bool __thiscall std::locale::_Iscloc(void)const " (?_Iscloc@locale@std@@QBE_NXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "public: void __thiscall std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QAEXH_N@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "public: virtual __thiscall std::ios_base::~ios_base(void)" (??1ios_base@std@@UAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "protected: void __thiscall std::ios_base::_Addstd(void)" (?_Addstd@ios_base@std@@IAEXXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(ios.obj) : error LNK2005: "protected: void __thiscall std::ios_base::_Init(void)" (?_Init@ios_base@std@@IAEXXZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale.obj) : error LNK2005: "public: class std::locale & __thiscall std::locale::_Addfac(class std::locale::facet *,unsigned int,unsigned int)" (?_Addfac@locale@std@@QAEAAV12@PAVfacet@12@II@Z) already defined in msvcprtd.lib(MSVCP60D.d
ll)
libcpmtd.lib(locale.obj) : error LNK2005: "public: __thiscall std::_Locinfo::_Locinfo(char const *)" (??0_Locinfo@std@@QAE@PBD@Z) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(locale.obj) : error LNK2005: "public: __thiscall std::_Locinfo::~_Locinfo(void)" (??1_Locinfo@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(xwctomb.obj) : error LNK2005: __Getcvt already defined in msvcprtd.lib(MSVCP60D.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2005: _free already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dosmap.obj) : error LNK2005: __errno already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(lconv.obj) : error LNK2005: _localeconv already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(getenv.obj) : error LNK2005: _getenv already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(fflush.obj) : error LNK2005: _fflush already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in LIBCMTD.lib(mbctype.obj)
libcpmtd.lib(iostream.obj) : error LNK2005: "public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
libcpmtd.lib(iostream.obj) : error LNK2005: "public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP60D.dll)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCMTD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/dcmsrview32.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

dcmsrview32.exe - 29 error(s), 2 warning(s)

i am using visual c++ 6.0. are there any linker setting i need to set in order to eliminate these errors. i know this description is rather vague, but i really don't know what else to include. if you need any other info let me know. thanks. btw, i am using MFC.
 
OP
mesman00

mesman00

What's that...?
ok, i have limited it now to 3 errors and 6 warnings by ignoring the libraries msvcrtd.lib and msvcprtd.lib. now this is the output after linking:

Code:
--------------------Configuration: dcmsrview32 - Win32 Debug--------------------
Linking...
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Winit::_Winit(void)" (??0_Winit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Winit::~_Winit(void)" (??1_Winit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol "__assert" imported
LINK : warning LNK4049: locally defined symbol "__setmbcp" imported
convert.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::`vbase destructor'(void)" (__imp_??_D?$basic_ofstream@DU?$char_traits@D@std@@@std@@QAEXX
Z)
convert.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::basic_ofstream<char,struct std::char_traits<char> >(char const *,int)" (__imp_??0?$basic_ofst
ream@DU?$char_traits@D@std@@@std@@QAE@PBDH@Z)
Debug/dcmsrview32.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

dcmsrview32.exe - 3 error(s), 6 warning(s)
 

aprentice

Moderator
mesman00 said:
ok, i have limited it now to 3 errors and 6 warnings by ignoring the libraries msvcrtd.lib and msvcprtd.lib. now this is the output after linking:

Code:
--------------------Configuration: dcmsrview32 - Win32 Debug--------------------
Linking...
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Winit::_Winit(void)" (??0_Winit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall std::_Winit::~_Winit(void)" (??1_Winit@std@@QAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol "__assert" imported
LINK : warning LNK4049: locally defined symbol "__setmbcp" imported
convert.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::`vbase destructor'(void)" (__imp_??_D?$basic_ofstream@DU?$char_traits@D@std@@@std@@QAEXX
Z)
convert.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::basic_ofstream<char,struct std::char_traits<char> >(char const *,int)" (__imp_??0?$basic_ofst
ream@DU?$char_traits@D@std@@@std@@QAE@PBDH@Z)
Debug/dcmsrview32.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

dcmsrview32.exe - 3 error(s), 6 warning(s)

your missing a library
 
OP
mesman00

mesman00

What's that...?
that is what i thought. in my code i am using the iostream library to write data to a file. however, if i comment out #include <iostream> and all the code that uses the library, it will link without any errors. so what is the relation here?
 

smcd

Active member
You need to link to the runtime library, either libcp.lib or libcpmt.lib?

You were linking with both the static (LIBCPMT) runtime library AND the dynamic (MSVCRT) together, it appears. Since it was in debug mode, they'd be called "libcmtd.lib" and "msvcrtd.lib"

By linking a multi-threaded version (that gets statically included) along with a possibly singled-threaded only dynamic library (I am not sure if MSVCRT.LIB, which results in the use of MSVCRT.DLL runtime, is thread-safe or not?) you might introduce other errors into the execution of your program later down the line as well.
 
Last edited:
OP
mesman00

mesman00

What's that...?
sethmcdoogle said:
You need to link to the runtime library, either libcp.lib or libcpmt.lib?

You were linking with both the static (LIBCPMT) runtime library AND the dynamic (MSVCRT) together, it appears. Since it was in debug mode, they'd be called "libcmtd.lib" and "msvcrtd.lib"

By linking a multi-threaded version (that gets statically included) along with a possibly singled-threaded only dynamic library (I am not sure if MSVCRT.LIB, which results in the use of MSVCRT.DLL runtime, is thread-safe or not?) you might introduce other errors into the execution of your program later down the line as well.

you say i am linking with the static and dynamic libraries. thus, how do i link with only one of the libraries? how do i link to libcp/libcpmt. shouldn't the compiler do that automatically, as the are default libraries, and i am NOT ignoring default libraries?
 

Doomulation

?????????????????????????
Well if you're not ignoring the standard libraries, then how the hell can't it find iostreams? You tell us =)
I've noticed similar problems, though... it probably is that the libraries you're linking against both have some symbols (same). Maybe you can throw one of those libraries away and it will still work. Worth a try.
 
OP
mesman00

mesman00

What's that...?
Doomulation said:
Well if you're not ignoring the standard libraries, then how the hell can't it find iostreams? You tell us =)
I've noticed similar problems, though... it probably is that the libraries you're linking against both have some symbols (same). Maybe you can throw one of those libraries away and it will still work. Worth a try.

that is a result of ignoring the msvcrtd lib, i think. if i ingore this lib i reduce the amount of erros, but other problems are created. see above. to me it appears that two libraries define the same method/struct or something, thus causing a conflict.
 

Top