VS Static Compilation Settings

有时候把自己写的程序拷到其他电脑上运行,会出现缺少msxxxx.dll的提示,这是因为目标电脑上没有安装对应版本的C++运行库。

这时候要么在目标电脑上安装C++运行库,要么在编译的时候把动态编译(不包含运行库)改成静态编译(自带运行库)。另外,动态编译生成的体积比静态编译下的的体积要小的多。

首先必须搞清楚项目->项目属性->配置属性->C/C++->代码生成->运行库中四个选项的关系:

显示名 编译选项
多线程调试Dll (/MDd) MD_DynamicDebug
多线程Dll (/MD) MD_DynamicRelease
多线程(/MT) MD_StaticRelease
多线程(/MTd) MD_StaticDebug

在msdn中有详细解释:
http://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx

带有小d的(比如/MDd,/MTd)是Debug模式的。
带有D是动态(/MD,/MDd),带有T是静态(/MT,/MTd)。

Sometimes when copying a self-written program to another computer to run, a prompt appears stating that msvcxxx.dll is missing. This is because the target computer does not have the corresponding version of the C++ runtime library installed.

In such cases, you can either install the C++ runtime library on the target computer or change the compilation method from dynamic linking (which does not include the runtime library) to static linking (which includes the runtime library) during compilation. Additionally, the size of executables generated through dynamic linking is much smaller than those generated through static linking.

First, it is essential to understand the relationships between the four options under: Project -> Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library:

Display Name Compilation Option
Multithreaded Debug DLL (/MDd) MD_DynamicDebug
Multithreaded DLL (/MD) MD_DynamicRelease
Multithreaded (/MT) MD_StaticRelease
Multithreaded (/MTd) MD_StaticDebug

Detailed explanations are available on MSDN:
http://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx

Options with a lowercase “d” (e.g., /MDd, /MTd) are for Debug mode.
Options with “D” indicate dynamic linking (/MD, /MDd), while options with “T” indicate static linking (/MT, /MTd).


VS Static Compilation Settings
https://tokisaki.top/blog/vs-static-compilation-setting/
作者
Tokisaki Galaxy
发布于
2021年4月4日
许可协议