与Visual Studio 2010中的MD相反,无法在MT模式下编译简单的Qt程序 [英] Cannot compile a simple Qt program in MT mode as opposed to MD in Visual Studio 2010

查看:309
本文介绍了与Visual Studio 2010中的MD相反,无法在MT模式下编译简单的Qt程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Visual Studio 2010中而不是MDd中使用MTd进行编译(以便将dll打包在其中,并且我不需要将其与我的exe一起分发),但是我一直收到致命错误LNK1169:一个或更多在编译过程中找到的已定义符号。 MDd可以很好地编译,但是在没有MSVCP100.dll的情况下无法在其他计算机上运行。



还有另一种方法可以强制链接器静态编译吗?我要做的就是将Qt程序作为不带dll的exe分发。



这是构建日志:

  1> ClCompile:
1>所有输出都是最新的。
1> cooltest1.cpp
1> moc_cooltest1.cpp
1> main.cpp
1>产生程式码...
1>所有输出都是最新的。
1> qrc_cooltest1.cpp
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:公共:__thiscall std :: exception :: exception(char const * const&)(?? 0exception @ std @@ QAE LIBCMT.lib(stdexcpt.obj)
1> MSVCRT.lib(MSVCR100.dll)中已定义的@ ABQBD @ Z):错误LNK2005: public:虚拟__thiscall std :: exception ::〜exception(void) (?1exception @ std @@ UAE @ XZ)已在LIBCMT.lib(stdexcpt.obj)
1> MSVCRT.lib(MSVCR100.dll)中定义:错误LNK2005: public:__thiscall std :: exception :: exception(class std :: exception const&)(?? 0exception @ std @@ QAE @ ABV01 @@ Z)已在LIBCMT.lib(stdexcpt.obj)
1> MSVCRT.lib( MSVCR100.dll):错误LNK2005:_memmove已在LIBCMT.lib(memmove.obj)
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_strncmp已在LIBCMT.lib(strncmp.obj)中定义
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_isupper已在LIBCMT.lib(_ctype.obj)中定义
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_isalpha已经定义LIBCMT.lib(_ctype.obj)
1> MSVCRT.lib(MSVCR100.dll)中的d:错误LNK2005:LIBCMT.lib(_ctype.obj)
1> MSVCRT.lib( MSVCR100.dll):错误LNK2005:_isspace已在LIBCMT.lib(_ctype.obj)
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_malloc已在LIBCMT.lib(malloc.obj)中定义
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_free已在LIBCMT.lib(free.obj)中定义
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:__control87已经在LIBCMT.lib(_ieee87_.obj)
1> MSVCRT.lib(MSVCR100.dll)中定义:错误LNK2005:__ clearfp已在LIBCMT.lib(_ieee87_.obj)
1> MSVCRT.lib( MSVCR100.dll):错误LNK2005:_strncpy_s已在LIBCMT.lib(strncpy_s.obj)
1> MSVCRT.lib(MSVCR100.dll)中:错误LNK2005:_strcpy_s已在LIBCMT.lib(strcpy_s.obj)中定义
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_realloc已在LIBCMT.lib(realloc.obj)中定义
1> MSVCRT.lib(MSVCR100.dll) :错误LNK2005:公开:__ thiscall std :: exception :: exception(char const * const&,int)(?? 0exception @ std @@ QAE @ ABQBDH @ Z)已在LIBCMT.lib(stdexcpt.obj)中定义)
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:_exit已在LIBCMT.lib(crt0dat.obj)中定义
1> MSVCRT.lib(MSVCR100.dll):错误LNK2005:__errno已在LIBCMT.lib(dosmap.obj)
1> MSVCRT.lib(MSVCR100.dll)中定义:错误LNK2005:_abort已在LIBCMT.lib(abort.obj)
1> MSVCRT.lib中定义(ti_inst.obj):错误LNK2005:私有:__thiscall type_info :: type_info(class type_info const&)(?? 0type_info @@ AAE @ ABV0 @@ Z)已在LIBCMT.lib(typinfo.obj)中定义b $ b 1> MSVCRT.lib(ti_inst.obj):错误LNK2005:私有:类type_info& __thiscall type_info :: operator =(class type_info const&)(?? 4type_info @@ AAEAAV0 @ ABV0 @@ Z)已在LIBCMT.lib(typinfo.obj)
1> LINK中定义:警告LNK4098:defaultlib 'MSVCRT'与其他库的使用冲突;使用/ NODEFAULTLIB:library
1> c:\users\username\documents\visual studio 2010\Projects\CoolTest1\\CoolTest1.exe :致命错误LNK1169:找到一个或多个乘法定义的符号
1>
1>构建失败。


解决方案

修改/ MT时,这是标准的链接器错误。您现在要链接使用/ MT编译的某些代码,因此与CRT代码有关在libcmt.lib中,某些代码是使用/ MD编译的,因此依赖于msvcrt.lib中的CRT代码。这是不允许的,程序中只能链接一个CRT。



您需要找到仍使用/ MD编译的代码。这些代码很可能存在于.lib中,如运行时支持QT的rt代码。如果QT没有支持静态链接CRT的.lib,那么您就束手无策了。这并不罕见,很难在可处理/ MT的DLL中编写代码。


I'm trying to compile using MTd in Visual Studio 2010 instead of MDd (so that the dll's are packaged in and i won't need to distribute them with my exe), but I keep getting "fatal error LNK1169: one or more multiply defined symbols found" during compilation. MDd compiles fine but does not work without MSVCP100.dll on other computers.

I'm using a static build of Qt and I'm trying to build the default Qt program that comes with the VS add-in.

Is there another way to force the linker to compile statically? All I'm trying to do is distribute a Qt program as an exe without dll's.

Here is the build log:

1>ClCompile:
1>  All outputs are up-to-date.
1>  cooltest1.cpp
1>  moc_cooltest1.cpp
1>  main.cpp
1>  Generating Code...
1>  All outputs are up-to-date.
1>  qrc_cooltest1.cpp
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMT.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 LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strncmp already defined in LIBCMT.lib(strncmp.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isupper already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isalpha already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isdigit already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _isspace already defined in LIBCMT.lib(_ctype.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __control87 already defined in LIBCMT.lib(_ieee87_.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __clearfp already defined in LIBCMT.lib(_ieee87_.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strncpy_s already defined in LIBCMT.lib(strncpy_s.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _strcpy_s already defined in LIBCMT.lib(strcpy_s.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &,int)" (??0exception@std@@QAE@ABQBDH@Z) already defined in LIBCMT.lib(stdexcpt.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _abort already defined in LIBCMT.lib(abort.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 LIBCMT.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 LIBCMT.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>c:\users\username\documents\visual studio 2010\Projects\CoolTest1\\CoolTest1.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.     

解决方案

This is a standard linker error when you tinker with /MT. You are now linking some code that was compiled with /MT and thus has a dependency on the CRT code in libcmt.lib with some code that was compiled with /MD and thus has a dependency on the CRT code in msvcrt.lib. This is not allowed, there can be only one CRT linked into your program.

You'll need to find the code that is still compiled with /MD. This code may well exist in a .lib, like the runtime support code for QT. If QT doesn't have a .lib that supports statically linking the CRT then you're stuck with /MD. That's not uncommon, writing code that lives in DLLs that can deal with /MT is difficult.

这篇关于与Visual Studio 2010中的MD相反,无法在MT模式下编译简单的Qt程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆