VC, Linux static compilation with dynamic compilation (MD, MT)

Source: Internet
Author: User

Start with Linux starting from the beginning, because the Linux programming understanding of the program to be clear, in contrast to VC is more easily confused.

When you compile dynamically, the program you publish is small, and you need to provide the Dll/so file you use when you run it.

When statically compiled, the program you publish is large, contains all symbols, runs without the support of other dll/so, and can be run independently.

The purpose of static compilation is to enable the published program to run independently, independent of other *.so, and technically to package all dependent symbols into the target program. At this point you will find that the compiled program is larger in size (the link is slower).

The compilation process is divided into compile and link, so-called Static compilation and dynamic compilation is the link process options.

Linux is dynamically compiled by default, introducing the static library when using-static or by specifying a full path directly. Under Linux, it is clear to see whether a symbol (function or global variable) is in the program. You can view all symbols using the NM command, or you can see them in more detail with the objdump command.

NM Helloword

The symbol denoted by T indicates that there is specific code in the file, and the symbol in D identifies that the symbol is an external symbol, defined in another *.so library. Our undifined reference error in the compilation process refers to this problem.

Debug Symbols: When a program compiles with the-G parameter, the compiled program can be debugged by GDB. Where-G means to instruct G++/GCC to write debug information in the output file when compiling.

Use the objdump-h command to see if there are any debug symbols in a program (that is, there are no. Several segment exist at the beginning of debug)

------------------------------------------------------------------------------------

Under VC, there are 4 parameters that are related to static/dynamic compilation. /md/mdd/mt/mtd

Where MT, MTD can be thought of as static compilation. In other words, the *.exe program, which is set to MT, after MTD, is signed at run time. MD MDD is unsigned. The lower case d indicates whether debugging is allowed, and the implication of debugging is that the debug information (function name, location, variable information) is added to the output program while compiling the program, allowing the program to be traced by a debug breakpoint. This corresponds to the-G option under Linux.

If you compile with MD MDD, your program cannot run on someone else's machine, unless someone else's machine installs the library that depends on it (also called the runtime DLL Runtime Library), which is the following files:

Msvcm90.dll

Msvcp90.dll

Msvcr90.dll

Microsoft.VC90.CRT.manifest

Note that the manifest is also necessary, not wrong.

The program compiled with MT, MTD is not required for these runtime DLLs. But if you call other 3rd party DLLs in your program, those DLLs still have to be attached. Further, if those DLLs are compiled with MD, you still have to install the on-the-Go runtime DLL (because the DLL you rely on depends on the runtime DLL). However, the normal release of DLL should be MT compiled, so do not worry about the other people's DLL problems, put their own programs to be prepared.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.