Introduction to the compiling environment of VC ++ 6.0)

Source: Internet
Author: User

You may have been using VC to develop software, but you may not be familiar with this compiler. There are many reasons. In most cases, we only "use" it, instead of "Understanding" it. Because it is just a tool, we would rather focus more on the C ++ language and software design. We are used to this "Mode": Create a project, and then writeCodeAnd then compile and re-Debug. However, the so-called: "to do a good job, you must first sharpen it ". If we are better at the VC development environment, can we be more comfortable?

Projects that can be created using Visual C ++

File files that can be created in Visual C ++

Build settings of Visual C ++

1. The compile test. cpp option only compiles the current file without calling the linker or other tools. The output window displays the error or warning information detected during the compilation process. Right-click the error information to get the location of the error code.
2. The build test.exe option compiles and links the last modified source file.
3. Rebuild all option this option allows you to compile all source files, regardless of when they have been modified
4. Batch build option this option can re-create multiple project files in one step, and allow users to specify the project type to be created. VC provides two target applicationsProgramType: Win32 release (release) and Win32 debug (Debug ).

 

Let's take a look at the VC processing process, which is roughly divided into two steps: Compilation and connection. After the source file is compiled and translated, all the. objfile named .objfile and the. libfile are connected to the. exe file or. dll file. Next, we will discuss the details of these two steps.

Project configuration dialog boxIn this dialog box, the drop-down list box in the upper-left corner is used to select a project configuration, including Win32 debug, Win32 release, and all comprehenations ), some options have different default values in different project configurations. The Tree View on the left shows all the files and categories of the current project. If we set the project "Schedule" to highlighted (like 9-1), a total of ten tabs will appear on the right of the dialog box, listing various project-related options, many Tabs have a reset button. After you press it, you can restore the settings in the tab to the initial values when the project is generated. If we select a file class or a file in the Tree View, the tabs on the right of the dialog box will be automatically reduced to one or two, listing all the options related to the selected file class or file.

Compilation parameter settings. The project-> Settings-> C/C ++ page of the VC menu is used. We can see the content in project options at the bottom of this page, which is generally as follows:

/Nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"/D "_ WINDOWS"/D "_ afxdll"/D" _ MBCS "/FP" Debug/writingdlgtest. PCH "/YU" stdafx. H "/FO" Debug/"/FD" Debug/"/FD/GZ/C

The meaning of each parameter can be explained by referring to the project option syntax.. For example, the/nologo indicates that these settings are not displayed in the output window during compilation (we can remove this parameter to see the effect. Generally, we do not directly modify these settings, but do it through the items in the top category on this page.

1)General: Some general settings. Warning Level is used to control warning information. None indicates that no warning is displayed. L1 indicates that only severe warnings are displayed. l2 indicates that warnings are more severe than L1, l4 indicates that all warnings are displayed, including those that are ignored for security. warnings as errors treats the warning information as an error so that the connector cannot be started for connection after compilation; optimizations is code optimization. You can perform more detailed settings in the optimizations item of category; generate browse info is used to generate. you can set more parameters in the listing files of category. Debug info, generate debugging information: None, do not generate any debugging information (compilation is faster); line numbers only, only generate debugging information of global and external symbols. OBJ file or. EXE file to reduce the size of the target file; C 7.0-compatible, record all the symbols used by the debugger. OBJ file and. EXE file; program database, create. all debugging information is recorded in the PDB file; program database for "Edit & continue", created. the PDB file records all debugging information and supports editing during debugging.

2)C ++ Language: Pointer_to_member representation is used to set the class definition/reference sequence. Generally, best-case always indicates that the class must have been defined before the class is referenced; Enable Exception Handling for synchronization exception handling; enable run-time type information forces the compiler to add the object type check during code execution. Disable construction displacements sets the class constructor/destructor to call virtual functions.

3)Code Generation: Processor indicates code command optimization, which can be 80386, 80486, Pentium, Pentium Pro, or blend. Use run-time library is used to specify the Runtime Library (single thread or multi-thread, debug version or release version) used when the program is running. One principle is, A process should not use several versions of runtime libraries at the same time. Single-threaded, static connection libc. lib Library; debug single-threaded, static connection libcd. lib Library; multithreaded, static connection libcmt. lib Library; debug multithreaded, static connection libcmtd. lib Library; multithreaded DLL, dynamic connection to msvcrt. dll library; debug multithreaded DLL, dynamic connection to msvcrtd. dll library. Multi-threaded calling is not supported when a single-threaded database is connected. connecting to a multi-threaded database requires the creation of multi-threaded applications. Calling convention can be used to set the call conventions, including __cdecl, _ fastcall, and _ stdcall. The main difference between various call conventions is that when a function is called, the function parameter is pushed from left to right into the stack or from right to left into the stack; when the function is returned, the parameters pushed into the stack are cleared by the caller of the function or by the function itself; and the name modification of the function name during compilation (you can see various naming methods through listing files ). Struct member alignment is used to specify the size of the member variables in the data structure in the memory. The data access speed varies with the alignment mode based on the number of digits in the computer data bus. This parameter is especially important for applications such as packet network transmission. It is not about the access speed, but about the precise definition of data bit. It is generally specified by # pragma pack in the program.

4)Customize: Disable language extensions, indicating that the Language extension made by Microsoft for Standard C is not used; eliminate duplicate strings, mainly used for string optimization (put the string in the slow-filling pool to save space ), with this parameter

Char * sbuffer = "this is a character buffer ";

Char * tbuffer = "this is a character buffer ";

Sbuffer and tbuffer point to the same memory space. Enable function-level linking tells the compiler to compile each function in the packaging format. enables minimal rebuild saves the association information. the IDB file enables the compiler to recompile only the source files modified by the latest class definition to improve the compilation speed. Enable incremental compilation also passes. the information stored in the IDB file. Only the latest modified functions are recompiled. Suppress startup banner and information messages are used to control whether the parameters are output in the output window.

5)Listing files: Generate browse info has been mentioned above. You can perform more settings here. Exclude local variables from browse info indicates whether to put information about local variables in the. SBR file. The listing file type can be used to set the content of the generated list information file: Assembly-only listing only generates the assembly code file (. ASM extension); Assembly with machine code to generate machine code and assembly code files (. cod extension); Assembly with source code generationSource codeAnd assembly code files (. ASM extension); Assembly, machine code, and source generate machine code, source code, and assembly code files (. COD extension ). The listing file name is the path of the generated information file. Generally, it is in the debug or release directory. The generated file name automatically retrieves the file name of the source file.

6)Optimizations:Code optimization settings. You can select maximize speed to generate the fastest code, mini-Mize size to generate the smallest program, or custom Optimization of mimize. Customized content includes:

Assume no aliasing, no alias (Increase speed );

Assume aliasing implements SS function CILS. Only aliases are not used inside the function;

Global optimizations, global optimization, such as storing frequently used variables using registers or computing Optimization in a loop, such

I =-100;

While (I <0) {I + = x + y ;}

Will be optimized

I =-100;

T = x + y;

While (I <0) {I + = T ;}

Generate intrinsic functions, replace some function calls with internal functions (increase the speed );

Improve float consistency, optimized for floating point operations;

Favor small code, Program (exe or DLL) Size Optimization takes precedence over code Speed Optimization;

Favor fast code, Program (exe or DLL) code Speed Optimization takes precedence over Size Optimization;

Frame-pointer omission, which does not use frame pointers to increase the function call speed;

Full optimization combines several parameters to generate the fastest program code.

Inline Function Expansion, three optimizations of Inline Function Extension (using inline can save the overhead of function calling and speed up the program): Disable does not use inline; only _ inline, only the inline or _ inline mark before function definition uses inline; any suitable, except for the functions marked by inline or _ inline, the compiler "thinks" That inline functions should be used, use inline.

7)Precompiled headers: Pre-compiled header file settings.

The concept of pre-compile header: the so-called pre-compile header is to put the part of the code in a project in advance into a file (usually. PCH Extension). This file is called the precompiled header file. The pre-compiled code can be any C/C ++ code -------- or even an inline function, however, it must be stable and won't be changed frequently during project development. If the code is modified, re-compile the pre-compiled header file. You can put some public, slightly changed header files (such as filex. h) To stdafx. h, this part of the Code does not have to be re-compiled every time (unless it is rebuild all ). Note that it takes a lot of time to generate a pre-compiled header file. At the same time, you must note that the pre-compiled header file is usually large, usually 6-7 M. Pre-compilation can improve the speed of repeated compilation.

You may ask: The current compiler has the time stamp function. When the compiler compiles the entire project, it only compiles the modified files, instead of compiling files that have not been modified since the previous compilation. So why do we need to pre-compile the header file? Here, we know that the compiler is compiled in files. After a file is modified, it will re-compile the entire file. Of course, all the header files contained in this file (. eg macro, Preprocessor) must be processed again. The pre-compiled header file of VC stores this part of information. To avoid re-processing these header files every time.

1. Use the settings in the project,/Yu "stdafx. h ". If/Yu is used, that is, pre-compilation is used. the beginning of a CPP file. I emphasize that it is the beginning of a file, including the file that you specified to generate a PCH file. h file (default is stdafx. h) otherwise there will be problems. If you do not include this file, tell you unexpected file end. If you do not include

2. if you accidentally lose the PCH file, the simplest way is to select the first option "not using .... ", so there is no need to pre-compile the header or look for the PCH file, so there will be no errors, but the consequence of doing so is that more time will be made for each compilation and connection. You can also select the second option "automatic use of", and then fill in stdafx in the "Through Header" force. h. In this way, if there is no PCH file system, a PCH will be automatically generated. If there is one, this PCH will be used. This option is "intelligent. The third option is to forcibly create a PCH file, and the fourth option is to directly use the PCH file. Of course stdafx. H is entered in "Through headers.

Let the compiler generate a PCH file. That is to say, you can re-compile stdafx. cpp (that is, the CPP file of the specified/YC. Of course, you can rebuild all.

8)Preprocessor: Pre-compilation. We can predefine some macro names here, specifying some or all symbols with undefined state. Additional include directories, you can specify an additional include directory, which is generally relative to the directory of the project, such as. \ include.

 

Link connection ParametersSettings.

The project-> Settings-> link page of the VC menu item is used. We can see the content in project options at the bottom of this page, which is generally as follows:

/Nologo/subsystem: Windows/Incremental: yes/PDB: "Debug/writingdlgtest. PDB"/debug/machine: i386/out: "Debug/writingdlgtest.exe"/pdbtype: sept

Next, let's take a look at the various settings in category.

1.General: Some general settings. You can set the path and file name of the generated file. For example, in the "output file name:" edit box, enter "C: \ bin \ test.exe". The connected library file; generate debug info to Generate debug information. PDB file (the specific format can be set in category-> Debug); ignore all default libraries, discard all default library connections; link incrementally, through generation. the ilk file implements incremental connections to increase the speed of subsequent connections, but the files (exe or DLL) generated in this mode are large; generate mapfile, generate. the map file records information about the module. Enable profiling, this parameter is usually used together with the generate mapfile parameter, and cannot be used if debug information is generated. PDB file, and Microsoft format must be used.

2.Customize: You can set the database file. Select use program database to allow the use of the program database, so that the connector stores debugging information in the program database. If this option is not selected, the incremental connection method cannot be used. Force file output, even if a module references some undefined or repeated symbols, the connector will still generate an output file (exe or DLL) Forcibly (but not necessarily run correctly ); print progress messages to output the progress information in the connection process to the output window.

3.Debug:Set whether to generate debugging information and the format of debugging information. The format can be Microsoft format, coff format (Common Object File Format), and both formats (both). Separate types indicates that the debug format information is independent. PDB files are stored directly in the source files. in the PDB file. If selected, the latter method is used. This method is faster for debugging and startup.

4.Input:You can specify the database file to be connected and discard the database file to be connected. You can also add an additional library file directory, which is generally relative to the directory of the project, such as. \ Lib. Force symbol references. You can specify a library to connect to a specific symbol definition. For example, enter "testdll. in the "Additional library path:" edit box, enter "C: \ bin ". Static libraries compiled by another project in Workspace

5.Output:Base Address can change the default base address of the program (the default base address of the EXE file is 0x400000, and the default DLL is 0x10000000). When the operating system loads a program, it always tries to start with this base address. Entry-point symbol can specify the entry address of a program. Generally, it is a function name (and the _ stdcall call Convention must be used ). Generally, for Win32 programs, the EXE entry is winmain and the DLL entry is dllentrypoint. It is best to enable the connector to automatically set the program entry point. By default, it is implemented through a C Runtime library function: the console program uses maincrtstartup (or wmaincrtstartup) to call the main (or wmain) function of the program; windows programs use winmaincrtstartup (or wwinmaincrtstartup) to call winmain (or wwinmain, which must use the _ stdcall call Convention) of the program ); DLL uses _ dllmaincrtstartup to call the dllmain function (the _ stdcall call Convention must be used ). Stack allocations, used to set the stack size used by the Program (in decimal format). The default value is 1 MB. Version Information tells the connector to add the version number to the start part of the EXE or DLL file. Generally, no changes are required.

It is worth noting thatThe preceding parameters are case-sensitive. If "-" is added to the parameter, the parameter is invalid. If the parameter value options are "*", the parameter is the default value; you can use the "reset" button in the upper-right corner of the page to restore all default settings on the page.

9)Resources TabThe resources tab controls the vc6 resource compiler. As shown in 9-5, we can specify the path of the resource file generated after compilation, the language type of the resource, and the additional resource inclusion directory.

The midl tab is related to com (Component Object Model) programming. We will not discuss it.

10) on the Browse Info tab, you can specify whether to generate a browsing information file while creating the project. With this file, in the text editor, we can quickly locate the definition or reference of a symbol through the corresponding commands of the Association menu.

11)Pre-link step

This tab is used to add the command to be executed before the connection.

L2)Post-build step

This tab is used to add the command to be executed after the project is created, such as "Copy debug \ testdll. lib c: \ bin \ testdll. lib "and create a bin directory under drive C. copy lib to the folder where c: \ bin is located

Other parameter settings.

13)Project-> Settings-> GeneralYou can set the method for connecting to the MFC Library (static or dynamic ). If it is a dynamic connection, do not forget to include the mfc dll when your software is released. The second option is used to specify the directory for storing intermediate and output files generated during the compilation and connection process. For debugging versions, the default directory is the "debug" subdirectory under the project. The third option at the bottom is used to specify whether each project configuration can have its own file dependency (main finger file ), because the debugging and release versions of most projects share the same file dependency, you do not need to change this option.

14)Project-> Settings-> debugYou can set the executable file to run during debugging. If the program you are writing is a DLL, you should specify an EXE file to debug the DLL. The other three options can be used to specify the working directory for debugging, the command line parameters sent to the program at the start of debugging, and the path of the executable file during remote debugging. After switching the category to additional DLLs, we can specify whether to load the debugging symbol information for some additional DLL at the start of the debugging. Only after the symbolic information is loaded Can we track the DLL.

15)Project-> Settings-> Custom Build, You can set to automatically execute some operations after the compilation/connection is successful. When writing COM, you want VC to automatically register the compiled COM file. You can set it as follows:

Description: Register com

Commands: regsvr32/S/C $ (targetpath)

Echo regsvr32 exe. Time> $ (targetdir) \ $ (targetname). Trg

Outputs: $ (targetdir) \ $ (targetname). Trg

16)Tools-> options-> Directories, Set the include and library paths of the system.

 

Tips

1) Sometimes, during compilation, the computer suddenly shuts down illegally (maybe someone accidentally hits the power or your memory is unstable ). After you restart the machine, open the project and re-compile it. Then, the VC will crash. You may think that your VC compiler is broken, but it is not (you should try to compile other projects !), You only need to delete the project's. NCB,. Opt,. APs,. CLW files, and all the files under the debug and release directories, and then recompile them.

2) If you want to share your source code project with others, but copying the entire project is too large. You can delete the following files:. DSW,. NCB,. Opt,. APs,. CLW,. PLG, and all files in the debug and release directories.

3) when your workspace contains multiple projects, you may not be able to intuitively and intuitively see which project is the current one. You can set the settings as follows: Tools-> options-> Format, select workspace window in category, and change its default font (for example, set it to fixedsys.

4) how to change the name of an existing project? Turn off the project. Open the. DSP file in text format and replace the original project name.

5) vc6 is useful for smart prompting of class members, but sometimes it fails. You can close the project first. CLW and. delete NCB and re-open the project. Click View> classwizard in the menu item. In the displayed dialog box, click "add all" and rebuild all. The problem should be solved.

 

Appendix:

Explanation of VC file extensions

. APS: Stores intermediate files of binary resources. VC converts the current resource file to a binary format and stores the files in APS to accelerate resource loading. Resource auxiliary file.

. BMP: Bitmap resource file.

. BSC: Browses information files, which are generated by the browser information maintenance tool (BSCMAKE) from the original browser information file (. SBR). The BSC file can be used for quick locating in the source code editing window. This file is required if source Brower is used to browse project information. You can remove generate browse info file from project options to speed up compilation.

. C: Source code file written in C language.

. CLW: Files generated by classwizard to store class information. Classwizard information file, INI file format.

. CNT: Defines the structure of "contents" in the Help file.

. Cpp or. cxx: Source code file written in C ++.

. Cur: Cursor resource file.

. Def: Module definition file, used to generate a dynamic link library.

. DLG: Defines the independent files of the dialog box resources. This file is not required for the VC project, Because VC generally places the dialog box Resources in the. RC resource definition file.

. DSP: The project file generated by the VC development environment. vc4 and earlier versions use the Mak file to define the project. Project file, in text format.

. DSW: Workspace file generated by the VC development environment, which is used to organize multiple projects into one workspace. Workspace files, similar to. DSP.

. Exp: The output file generated by the Lib tool from the def file, which contains the output information of functions and data items. The link tool uses the exp file to create a dynamic link library. It is generated only when the DLL is compiled, and some information in the DLL file is recorded.

. H,. HPP, or. hxx: Header files written in C/C ++ are usually used to define data types and declare variables, functions, structures, and classes.

. HLP: Windows Help file.

. Hm: In the help project, this file defines the correspondence between the Help file and the id value between the dialog box, menu or other resources.

. HPJ: The help project file generated by Help Workshop is used to control the creation process of the Help file.

. HPGTo generate the project of the Help file.

. ICO: Icon resource file.

. Ilk: An intermediate file generated during the connection process. It is only used by the link tool.

. Ini: Configuration file.

. Lib: Library file. The link tool will use it to connect various input libraries to generate the EXE file.

. Lic: User license file, which is required when using certain ActiveX controls.

. Mak: Make file. The project files used in vc4 and earlier versions are used to specify how to create a project. vc6 converts the Mak file into a DSP file for processing.

. Map: A text file generated by the link tool, which contains information about the connected program, such as group information and public symbol information in the program. The image information of the execution file.

. MDP: The old project file, equivalent to. DSP

. NCB: NCB is the abbreviation of "no compile Browser". It stores information used by classview, wizardbar, and component gallery, which is automatically generated by the VC development environment. The Browser file is not compiled. You can delete this file when the Automatic completion function fails. The project is automatically generated after compilation.

. OBJ: The target file generated by the compiler or assembler is the binary intermediate file of the module.

. Odl: Source code file written in the Object Description Language. VC uses it to generate the TLB file.

. Olb: A special dynamic link library with type library resources, also known as object library files.

. Opt: Files automatically generated by the VC development environment to store various options in the workspace. The parameter file of the project about the development environment. For example, tool bar location information.

. PBI,. PbO, And. PBT: Three files generated and used by the profile of the VC performance analysis tool.

. PCH: Pre-compiled header file, which is large and automatically generated by the compiler when the project is created. It contains some code compiled in the project and will not be re-compiled when the project is created in the future, to speed up the entire compilation process.

. PDB: A program database file is automatically generated when a project is created. It stores various program information to speed up the debugging process. Records Program-related data and debugging information.

. PLG: Compile the information file, the error and warning information files during compilation.

. RC: Resource definition file.

. RC2: Resource definition file, which can be used in special cases.

. Reg: Registry information file.

. Res: Binary resource file. After the resource compiler compiles the resource definition file, the res file is generated.

. Rtf: Rich Text Format (Rich Text Format) documents can be created by word or WordPad and are often used to generate help files.

. SBR: The VC compiler generates the original browsing information file for each OBJ file. The browser information maintenance tool (BSCMAKE) will use the SBR file to generate the BSC file.

. TLB: Ole library file, which stores the data types, modules, and interface definitions of OLE automation objects. The Automation server can understand how to use automation objects through the TLB file.

. Wav: Audio Resource file.

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.