In the development of the window program is often encountered when the compiled program is not able to run on another machine, which is generally caused by the installation of the corresponding runtime library on another machine, then this compile option MT What is the relationship between MTd, MD and MDd? This is the explanation of msdn above:
When developing a multi-threaded program (single-threaded article is not discussed), you need to select one of MT, MTd, MD, MDd.
forMT/MTd, since the connection runtime library is LIBCMT.lib/LIBCMTD.lib, these two libraries are static libraries.Therefore, the program compiled in this way can be moved to another machine.
But forMD/MDd, connected to the dynamic librarySo if there is no other machineMSVCRT.dll/MSVCRTD.dllWhen you are prompted, the error is missing from the dynamic library.
I have made such a mistake and thought that it is compiled in MT/MTd mode. The program is statically linked to all the libraries. In fact, it is wrong. It can only decide whether the runtime library is dynamic or static, and the library written by the user or Other third-party libraries, depending on the code (explicitly connected to the dynamic library Loadlibrary) or the provided lib file (for import or static libraries), when you move the program to another machine, you still need to bring the required Dynamic library.
Looking at an example, compiling a static library and a dynamic library both implement the function of adding two integers:
// adds.h
// add followed by s for static library
#pragma once
int add(int,int);
// adds.cpp
// static library
#include "adds.h"
int add(int a, int b)
{
return a+b;
}
Above, the runtime library selects MTd and compiles it into a static library adds.lib
// addd.h
// add followed by d to represent the dynamic library
#pragma once
#ifndef MYLIB_API
#define MYLIB_API _declspec(dllexport)
#endif
MYLIB_API int add(int,int);
// addd.cpp
// dynamic library
#include "addd.h"
int add(int a, int b)
{
return a+b;
}
Above, the runtime library selects MTd and compiles it into the dynamic library addd.lib, addd.dll
// test.cpp
// test program
#include <iostream>
/ / Test the static library, here is 1, test the dynamic library, here is 0
#define TEST_STATIC_LINK 1
#if TEST_STATIC_LINK
#include <adds.h>
#else
#define MYLIB_API _declspec(dllimport)
#include "addd.h"
#endif
using namespace std;
int main()
{
cout << add(2,3) << endl;
return 0;
}
Test program compiled with MTd
In the above example, the add library and the test program both select the MTd runtime library. If the inconsistency causes some compilation connection errors, the novice is not mindful.
For example, if you select MDd, the connection will have such an error:
1> is linking...
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) Already in LIBCMTD.lib(typinfo. Defined in 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) Already in LIBCMTD. Defined in lib(typinfo.obj)
That is, a program that mixes different runtime libraries (static and dynamic, debug and non-debug) may cause conflicts, so the same runtime library should be used in a program.
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 ...
###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)/...
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...
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...
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. ...
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...
Most people know that in the Windows development process, to achieve code reuse, it will be packaged into an interface, and then packaged into a library form, which has a static library and a dynamic ...