1

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

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++-> 代码生成中的“运行时库”字段对于所有 3 个项目(我的主项目、swift、操作码)都相同。我已尝试将它们全部设置为 \MT 并全部设置为 \MD 以进行调试模式,但都不起作用。实际上,当它在 Release 中成功构建时,我必须将 Opcode 和我的活动项目设置为 \MD(swift 可以是 \md 或 \mt 并且它仍然可以构建)。我不太了解用于链接的运行时库...所以如果这是问题所在,您可以尝试明确吗?

我也去寻找_ITERATOR_DEBUG_LEVEL,但找不到。我应该在哪里更改它?我在源代码的任何地方都找不到它。我没有在项目属性中看到它,但完全有可能我只是没有在属性中找到正确的位置。

显然,人们在字符集不匹配时也遇到过类似的错误。我已经尝试将它们全部设置为 multi 并全部设置为 unicode。那似乎没有任何效果。

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

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

操作码:

WIN32
_DEBUG
_WINDOWS
_USRDLL
OPCODE_EXPORTS

迅速:

_DEBUG
WIN32
_LIB
LOOKUP_TABLE_5_625

活跃项目:

WIN32
_DEBUG
_CONSOLE

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

4

1 回答 1

0

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

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

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

于 2013-04-10T18:51:21.787 回答