Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile a simple Qt program in MT mode as opposed to MD in Visual Studio 2010

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.     
like image 873
wes Avatar asked Jun 26 '11 18:06

wes


People also ask

How to integrate Qt with Visual Studio?

In Microsoft Visual Studio, select Extensions > Manage Extensions > Online, and search for Qt Visual Studio Tools to install or update Qt VS Tools.

How to add Qt version to Visual Studio?

Under tools select Extensions and Updates. click the Online arrow on the left and search for Qt. Install the Qt Visual Studio Tools extension. Restart the Visual Studio 2019 IDE and under Qt VS Tools –> Qt Options add the Qt version 5.14 with associated directory C:\qt\5.14.


3 Answers

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.

like image 195
Hans Passant Avatar answered Oct 17 '22 15:10

Hans Passant


you may rebuild QT to use static VC libraries. Go to ${QtDir}\mkspecs\win32-msvc2010\qmake.conf, and replace

QMAKE_CFLAGS_RELEASE    = -O2 -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
QMAKE_CFLAGS_DEBUG      = -Zi -MDd

with

QMAKE_CFLAGS_RELEASE    = -O2 -MT
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
QMAKE_CFLAGS_DEBUG      = -Zi -MTd

after that clean reconfigure and rebuild qt

like image 38
Raiv Avatar answered Oct 17 '22 16:10

Raiv


You are linking your program statically and linking against libcmt, but at the same time, linking in code from the Qt DLLs, which are, as the name already says, dynamically linked against msvcrt.lib.

You will need to either link dynamically or recompile Qt from source as static, which isn't hard, but time-consuming.

like image 44
rubenvb Avatar answered Oct 17 '22 16:10

rubenvb