Learning windows programming (8)-compile the CRT by yourself

Source: Internet
Author: User

Learning windows programming from scratch (8) -- start by yourself and compile CRT
Open the lib directory of the corresponding VC and you can see the lib file of the CRT. The path on my computer is "d: Program FilesMicrosoft Visual StudioVC98Lib". You can find your own path. After the above article, we have a certain understanding of it, and of course it is okay to use it. As a programmer, do you still want to see how it is generated? Here, we will explain how to generate a CRT library.

Install CRT source code

Since the question is compilation, the source code is required. If you open the path on your computer, for example, "d: Program FilesMicrosoft Visual StudioVC98CRT" in my computer, you will find that the following SRC directory already exists, if there are more than 700 files and 2 subdirectories, you have installed the source code of the CRT. You can skip this section and see the following "compilation process". If it doesn't happen, if you want to continue, refer to here to install the source code of the CRT.

First, you need a VC6 installation disk or a VC6 Installation File. Whether you have installed VC or installed VC, I will not elaborate on the installation process. The main CRT is installed in the following figure:

In the middle, the CRT is framed by the red line.

 

Let's take a look at the details. The first item is the source code of the CRT. The point is to check this item. The source code will be available in the installation directory, and the corresponding source code directory will also be displayed, it is the part that is enclosed in a yellow box.

 

Of course, to save trouble, simply install all the components in VC.

 

After the installation, You can compile it. However, do not put the installation disk aside. We will continue to use it later.

Compilation process

We already know that the CRT library is divided into three types: single thread, multi-thread, and dynamic library, and each of these three types has a debug version, in this way, a total of six versions of the CRT library can be compiled. Microsoft calls them ST model, MT model, DLL model, XST model, XMT model, and XDLL model respectively. Our goal is to compile these versions.

Compilation preparation

A few more work is required before compilation.

Make sure that your nmake can work.
From the VC6 Installation File/CD-ROM directory, find the following three files, and copy to the corresponding source directory, corresponding to my directory here is "d: Program FilesMicrosoft Visual StudioVC98CRTSRC ".
MAKEFILE
MAKEFILE. INC
MAKEFILE. SUB
Modify the MAKEFILE file. Search for each row of Winver. h. If
$ (V6TOOLS) includewinver. h

Delete the row, which contains six parts. (These are all generated during DLL compilation)
After all these work is done, you can start compiling. Of course, there may be other problems, such as a problem encountered when compiling the DLL version, however, there are so many modifications required by Microsoft.

Next we will compile the six versions separately to make it clearer. Go to the source code directory, enter the following commands, and view the output

ST
D: Program FilesMicrosoft Visual StudioVC98CRTSRC> nmake st

Compilation result

All the compiled outputs are under the build directory, and a bunch of obj files are located under the st_obj directory, so we don't care about this. It mainly generates lib files:

Libc. lib
Libci. lib
Libcp. lib
MT
D: Program FilesMicrosoft Visual StudioVC98CRTSRC> nmake mt

Compilation result

Libcmt. lib
Libcisr. lib
Libcpmt. lib
DLL
D: Program FilesMicrosoft Visual StudioVC98CRTSRC> nmake dll

Compile the result. At last, there will be some warnings, but there is no problem. According to Microsoft, it is normal to compile the CRT. (Too many messages. Here, only some warning messages are taken)

Link-nologo-filealign: 4096 @ buildinteldll_objlinki.rsp
. Sample_ I .def: warning LNK4102: export of deleting destructor "public: virtual
Void * _ thiscall exception: 'vector deleting destructor (unsigned int) "; image
May not run correctly
. Sample_ I .def: warning LNK4102: export of deleting destructor "public: virtual
Void * _ thiscall filebuf: 'vector deleting destructor (unsigned int) "; image m
Ay not run correctly
. Sample_ I .def: warning LNK4102: export of deleting destructor "public: virtual
Void * _ thiscall fstream: 'vector deleting destructor (unsigned int) "; image m
Ay not run correctly

Result

LIB file DLL file MAP file RES file equivalent file (LIB)
_ Sample _. lib _ sample _. dll _ sample _. map _ sample _. res MSVCRT. LIB
Sample_ I .lib sample_ I .dll sample_ I .map sample_ I .res MSVCIRT. LIB
Sample_p.lib sample_p.dll sample_p.map sample_p.res MSVCPRT. LIB

XST
D: Program FilesMicrosoft Visual StudioVC98CRTSRC> nmake xst

Compilation result

LIB file PDB File
Libcd. lib libcd. pdb
Libcid. lib libcid. pdb
Libcpd. lib libcpd. pdb

XMT
D: Program FilesMicrosoft Visual StudioVC98CRTSRC> nmake xmt

Compilation result

LIB file PDB File
Libcmtd. lib libcmtd. pdb
Libcimtd. lib libcimtd. pdb
Libcpmtd. lib libcpmtd. pdb

XDLL
D: Program FilesMicrosoft Visual StudioVC98CRTSRC> nmake xdll

Compilation result

LIB file DLL file MAP file RES file PDB file equivalent file (LIB)
_ Sampld _. lib _ sampld _. dll _ sampld _. map _ sampld _. res _ sampld _. pdb MSVCRTD. LIB
Sampld_ I .lib sampled_ I .dll sampled_ I .map sampled_ I .res sampld_ I .pdb MSVCIRTD. LIB
Sampld_p.lib sampled_p.dll sampled_p.map sampled_p.res sampld_p.pdb MSVCPRTD. LIB

Related Article

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.