构建Debug时链接错误

时间:2013-04-10 07:11:05

标签: visual-c++ linker linker-errors debug-symbols

每当我在Release中构建代码时,它都会编译并运行正常。但是,当我切换到Debug时,我得到一些我似乎无法弄清楚的错误。

swift.lib(scene.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>swift.lib(fileio.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>swift.lib(mesh_utils.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>swift.lib(object.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>swift.lib(mesh.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>swift.lib(pair.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>swift.lib(lut.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
1>msvcprt.lib(MSVCP100.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 main.obj
1>msvcprt.lib(MSVCP100.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 main.obj
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmtd.lib(uncaught.obj)
1>msvcprt.lib(MSVCP100.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 main.obj
1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z) already defined in main.obj

更多的那些然后......

1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMTD.lib(memmove.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fgetc already defined in LIBCMTD.lib(fgetc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fputc already defined in LIBCMTD.lib(fputc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _ungetc already defined in LIBCMTD.lib(ungetc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __lock_file already defined in LIBCMTD.lib(_file.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __unlock_file already defined in LIBCMTD.lib(_file.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fflush already defined in LIBCMTD.lib(fflush.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _setvbuf already defined in LIBCMTD.lib(setvbuf.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memcpy_s already defined in LIBCMTD.lib(memcpy_s.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fwrite already defined in LIBCMTD.lib(fwrite.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fgetpos already defined in LIBCMTD.lib(fgetpos.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __fseeki64 already defined in LIBCMTD.lib(fseeki64.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fsetpos already defined in LIBCMTD.lib(fsetpos.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\...\: fatal error     LNK1169: one or more multiply defined symbols found

我正在使用SWIFT和OPCODE库。我在C ++中有“运行时库”字段 - &gt;代码生成对于所有3个项目(我的主项目,swift,操作码)都是相同的。我已经尝试将它们全部设置为\ MT,并将所有设置为\ MD for Debug模式,但都不起作用。实际上,当它在Release中成功构建时,我必须将Opcode和我的活动项目设置为\ MD(swift可以是\ md或\ mt,它仍然构建)。我不太了解运行时库以便很好地链接...所以如果这是问题,你可以尝试明确吗?

我也去寻找_ITERATOR_DEBUG_LEVEL,但找不到它。我应该在哪里找到它来改变它?我在源头的任何地方都找不到它。我没有在项目属性中看到它,但是我只是没有找到属性中的正确位置,这是完全合理的。

显然,人们对错误匹配的字符集有类似的错误。我已经尝试将它们全部设置为多个并且全部设置为unicode。这似乎没有任何影响。

目前,我的活动项目只有swift.lib作为附加依赖项。我有opcode.dll和opcode_d.dll所以我没有静态链接那些。

在C / C ++设置下的预处理器中,我有以下预处理器定义:

操作码:

WIN32
_DEBUG
_WINDOWS
_USRDLL
OPCODE_EXPORTS

(SWIFT):

_DEBUG
WIN32
_LIB
LOOKUP_TABLE_5_625

活动项目:

WIN32
_DEBUG
_CONSOLE

如果需要,我可以提供更多信息。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

听起来您已经确保C运行时库(CRT)对所有项目都是一致的,这是首选做法。它对你的DLL项目来说不那么重要,因为它使用了CRT的独立副本。

下一步是查看项目设置的“预处理器”页面。您正在寻找可能在三个项目中发生冲突的预处理器(宏)定义。我相信你会在该列表中找到_ITERATOR_DEBUG_LEVEL。

我不知道如何在StackOverflow上发布后续问题,但您可以在您的问题中添加您在每个项目中找到的宏定义。