tags: qt visual studio Library
Transfer from: http://blog.csdn.net/caoshangpa/article/details/51416077
1. Set the runtime library in pro
Recently, the following error occurred when using Qt5.6.0 (VS2013 version) to call a static library of Debug version compiled with Visual Studio 2013:
Error: LNK2038: Detected mismatch of "RuntimeLibrary": The value "MTd_StaticDebug" does not match the value "MDd_DynamicDebug" (in widget.obj)
It can be seen from this error that the Debug version Qt5.6.0 library is compiled from the Qt source code through Visual Studio 2013, and the runtime library at compile time is set to MDd. But when the called static library is compiled by Visual Studio 2013, the runtime library is set to MTd. To avoid this error, you can only set the two runtime libraries to be the same at compile time.
Visual Studio can set the runtime library in the properties, as shown below:
So how to set the runtime library in the pro file? It can be set by the following four qmake variables.
This variable contains the C++ compiler flags for creating an application
When developing a window program, we often encounter situations where the compiled program cannot be run on another machine. This is usually caused by the fact that the corresponding runtime library is not installed on the other machine. Then this is related to the compilation option MT. What is the relationship between MTd, MD, and MDd? This is the explanation from msdn above:
MT: mutithread, multi-threaded library, the compiler will select a multi-threaded static link library from the runtime library to interpret the code in the program, that is, link to the LIBCMT.lib library
MTd: mutithread+debug, multi-threaded debugging version, connected to LIBMITD.lib library
MD: MT+DLL, multi-threaded dynamic library, link to MSVCRT.lib library, this is an import library, the corresponding dynamic library is MSVCRT.dll
MDd: MT+DLL+debug, multi-threaded dynamic debugging library, connected to MSVCRTD.lib library, corresponding dynamic library is MSVCRTD.dll
When developing a multi-threaded program (single thread is not discussed in this article), you need to choose one of MT, MTd, MD, and MDd.
For MT/MTd, since the link runtime library is LIBCMT.lib/LIBCMTD.lib, these two libraries are static libraries, so the program compiled in this way can also run normally when moved to another machine.
But for MD/MDd, the dynamic library is connected, so if there is no MSVCRT.dll/MSVCRTD.dll on another machine, it will prompt the error of missing dynamic library.
I once made such a mistake, thinking that when compiling in MT/MTd mode, the program is statically linked to all libraries. In fact, it is wrong. It can only determine whether the runtime library is dynamically linked or statically linked. For libraries written by users or For other third-party libraries, the connection method depends on the code (explicitly connect the dynamic library Loadlibrary) or the provided lib file (import library or static library). When moving the program to another machine, you still have to bring what you need Dynamic library.
Let's look at an example, compile a static library and a dynamic library, both of which realize the function of adding two integers:
1. Test static library, TEST_STATIC_LINK is defined as 1, provide adds.lib, generate executable file, move to another machine to run, because test program and adds.lib are statically connected to runtime library
2. Test dynamic library, TEST_STATIC_LINK is defined as 0, provide addd.lib, generate executable file, move to another machine to run, but need addd.dll, because addd library statically connects to runtime library, test program statically connects Run-time library, dynamically link addd library
In the above example, both the add library and the test program select the MTd runtime library. If they are inconsistent, it will cause some compilation and connection errors, which will make novices confused.
For example, if adds select MDd, the connection will have this error:
1>Linking...
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) has been defined in LIBCMTD.lib(typinfo.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) has been defined in LIBCMTD.lib(typinfo.obj)
That is, if different runtime libraries (static library and dynamic library, debugging library and non-debugging library) are mixed in a program, conflicts may occur, so the same runtime library should be used in a program.
###Date: 2017/10/23 1. Configuration of CRT compilation options Location of compilation options: Properties -> C/C++ -> Code Generation -> Runtime Library 2. Types of compilation options (1)/...
Microsoft gives the program that the runtime used by the default is (/ MD) (/ MDD) is a dynamic runtime. Sometimes it contains a third-party library, a link is a bunch of error, then run the li...
A language development environment often comes with a language library, which is a wrapper around the operating system's API. We also call these language libraries a runtime library. For the MSVC runt...
Transfer from: The project development process encountered MSVCRTD.LIB and LIBCMTD.LIB conflicts, and later found the reason is that the code compiler compile c / c + + runtime version is not the same...
reference: Openssl source download address:https://www.openssl.org/source/I used openssl-1.1.0i First install ActivePerl:https://www.activestate.com/activeperl/downloadsAfter loading it, if you start ...
Where do you start talking about this topic? The blogger Xiaobai one, recently debugged the program (WIN-MSVC) and did not understand some basic problems, in line with the principle of meeting the pro...
As these newcomers have do not understand, read the god of explanation sobering. Great God URL: https: //blog.csdn.net/u012273127/article/details/71419499 First, the problem of lead Recently a new in ...
Here is a summary of their differences. The ‘d’ at the back represents the DEBUG version, and the one without ‘d’ is the RELEASE version. First of all /MT /MT is "multithr...
Articles directory 0. Foreword 1. How to set up 1.1 Cmakelists code 1.2 Point 1: Policy 1.3 Key points 2: set_proprty 0. Foreword existMSVCEngineeringRight-click-> Properties,turn upConfiguration a...
Article Directory 1. Open the project 2. Modify options 3. Verification test In an embedded running environment, most of the host software may use the MD mode to load and run the C++ runtime library. ...