About the pre-translated head

zhaozj2021-02-17  48

First, what is the pre-compiled head?

The pre-translatic is physically physically .Obj file is the same, but compiled å. The pre-translated head. H, .c, .cpp files are compiled in the whole editor, such as the part involved in the pre-translated head. If you do not change, this part does not re-compile during subsequent compilation. Furthermore, it greatly improves compilation speed and facilitates management of header files, and also helps to prevent repetition contain problems.

Second, when do you use the pre-compiled head?

When most .C or .CPP files require the same header file.

When some code is used in a lot of reuse.

When importing some different libraries have implemented functions and makes confusion.

Third, the compilation switch and the use method involved in the precompiled head (for MSVC)

1. Automatic pre-compilation: when decided by the compiler to establish and use the pre-translated head.

Compile parameters: -yx. The precompiled head file named vcxy.pch is established when using this parameter default. Where x, Y is the version number of the VC. You can specify the output path and file name of the PCH file with -fp.

For example: cl -c -yx -fp "precomp.pch" ** will generate precomp.pch's preconditioned files in the current directory. ** represents the source file.

2, manual pre-compilation:

Compile parameters:

-Yc "The name of the precompiled header file" at this time, the default is established with the pre-translated header file as the header file. To do other names, use the -fp options.

For example: cl -c -yc "precomp.h" ** will establish precomp.pch's pre-translated header file.

-Yu "The name of the precompiled header" indicates that this pre-compiled step is used when a source file is used, not re-compiled. such as:

Cl -c-yu "precomp.h" **

Note: The corresponding precompiled head must have been established in front.

Fourth, simple use of pre-compilation technology in Makefile

OBJ / I386 / Debug.obj: debug.c debug.h

$ (Cc) -yc "precomp.h" -fo $ @ Debug.c

OBJ / I386 / OperateReg.obj: operateReg.c OperateReg.h

$ (Cc) -yu "precomp.h" -fo $ @ OperateReg.c

Obj / i386 / watermark.obj: Watermark.c Watermark.h

$ (Cc) -yu "precomp.h" -fo $ @ Watermark.c

The following is the same.

Where precomp.h is a header that wants to pre-compile.

V. Some complex use methods about pre-compiled agents

Such as:

Cl -c -yc "stuff.h" -fplevel1.pch level1.cpp ------------- (1)

Cl -c -yu "stuff.h" -fplevel1.pch -yc level2.cpp -------------- (2)

The beginning of Level2.cpp is like this, where #pragma HDRSTOP indicates the end of the preparatory, so the code can also be placed in the precompiled head.

#include "stuff.h"

#include "morestuff.h"

#pragma HDRSTOP ("Level2.pch")

(1) Establish a pre-compiled head that uses stuff.h to rename Level1.pch.

(2) On the basis of the precompiled head Level1.pch established from Stuff.h, refer to level2.cpp to establish another precompiled head Level2.pch

The naming rule at this time should be used when using the YC non-parameter.

Please refer to MSDN for other use rules for pre-translated.

Attachment:

1, pre-compilation and Guard macro

This is two concepts that have no relationships. If you say that you have to find the same place, the pre-translated head is also helpful to control repeatedly. #ifndef _Plotbrush_

#define _Plotbrush_

---

#ENDIF / / _PLOTBRUSH_

This Guard macro prevents the same .h file in the same .c file twice.

Anti-occurrence

#include

#include

The situation is.

The preconditioned head is equivalent to the global perspective to control those parts that are only compiled once.

The Guard macro is only valid for the current compilation unit. Defined in 1.c _Plotbrush_ pair 2.c has nothing to do.

2, when Build in 98DDK, use build -z to compile only changes in the source file. -c The role of clearing the target folder.

Please correct if there is a mistake.

Written by Li Zhiyong

2003/3/21

转载请注明原文地址:https://www.9cbs.com/read-28838.html

New Post(0)