[Reprinted] closely connected to the vc6.0 Compiler

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 write Code And then compile and re-Debug. However, the so-called: "to do good deeds, you must first sharpen your tools ". If we are better at the VC development environment, can we be more comfortable?

Let's talk less. 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. NextDiscussionThe details of these two steps.

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

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

For the meaning of each parameter, refer to msdn. 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, where Level 1 is the most serious level; warnings
Errors treats the warning information as an error. optimizations is code optimization and can be set in more detail in the optimizations item of category; generate
Browse info is used to generate. SBR files, record class, variables, and other symbolic information. You can perform more settings in the listing files item of category. Debug
Info to generate debugging information: none. No debugging information is generated (compilation is faster); line numbers
Only, generate only global and external debugging information to the. OBJ file or. EXE file, reduce the size of the target file; C 7.0-
Compatible: record all the symbols used by the debugger to The. OBJ file and. EXE file; program
Database, create a. PDB file to record all debugging information; program database for "Edit &
Continue ", creates a. PDB file to record all debugging information and supports editing during debugging.

2) C ++ language: pointer_to_member
Representation is used to set the class definition/reference relationship. 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 code to check the object type at runtime; Disable Construction
Displacements: Set the class constructor/destructor to call the virtual function.

3) Code
Generation: processor indicates code command optimization, which can be 80386, 80486, Pentium, Pentium
Pro, or blend indicates the optimization of the above. Use Run-Time
Library is used to specifyProgramThe Runtime Library (single thread or multi-thread, debug version or release version) used in the runtime should be a process that does not use several versions of the Runtime Library at the same time. Single-threaded, static connection to the libc. Lib Library; debug
Single-threaded, static connection libcd. Lib Library; multithreaded, static connection libcmt. Lib Library; debug
Multithreaded, static connection to libcmtd. Lib Library; multithreaded DLL, dynamic connection to msvcrt. dll library; debug
Multithreaded
DLL to dynamically connect to the 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 to the stack are cleared by the function caller or by the function itself; and the name modification of the function name during compilation (you can use listing
Files ). Struct Member
Alignment is used to specify how many bytes the member variables in the data structure are aligned in the memory. According to the number of digits of the computer data bus, different Alignment Methods have different data access speeds. This parameter is especially important for applications such as packet network transmission, not for the access speed, but for the precise definition of data bit. It is generally used in Programs # pragma
Pack.

4) customize: Disable Language
Extensions, indicating that the language extensions made by Microsoft for Standard C are not used; eliminate duplicate
Strings is mainly used for string optimization (put the string in a slow filling pool to save space). This parameter makes

Char * sBuffer= "This Is
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 to the. IDB file, so that the compiler only recompiles the source files modified by the latest class definition to improve the compilation speed. Enable incremental
Compilation, also saved through the. IDB file, only recompile the latest modified function; suppress startup banner and information
Messages, used to control whether the parameter is output in the output window.

5) listing files: Generate browse
Info functions have been mentioned above. You can perform more settings here. Exclude local variables from browse
Info indicates whether to put the local variable information in the. SBR file. 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 Generation machine code and assembly code file (. COD extension); Assembly with source code generationSource codeAnd assembly code files (. ASM extension); Assembly,
Machine code, and source generates machine code, source code, and assembly code files (. COD extension ). 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 or minimize
Size to generate the minimum size 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 (improving the speed );
Improve float
Consistency, floating point operation optimization;
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. No frame pointer is used to increase the function call speed;
Full
Optimization, which 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: inline or _ inline mark used before function definition; any
Suitable, except for the functions marked by inline or _ inline, the compiler "thinks" That inline functions should be used.

7) precompiled
Headers: Set the precompiled header file. Pre-compilation can improve the speed of repeated compilation. VC generally puts some common and slightly changed header files (such as afxwin. h) in stdafx. H. This part of Code does not have to be re-compiled every time (unless it is a rebuild
All ).

8) Preprocessor: Pre-compiled. Some constants can be defined or removed. Additional include
Directories, you can specify an additional include directory, which is generally relative to the directory of the project, such as./include.

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

/Nologo/subsystem: Windows/Incremental: Yes
/PDB: "Debug/writingdlgtest. PDB"/debug/machi
Ne: 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, the connected library file, and Generate debug.
Info to generate the debug information to the. PDB file (the specific format can be set in category-> Debug); ignore all default
Libraries, discard all default library connections; link incrementally, by generating.
The ilk file implements incremental connections to increase the speed of subsequent connections, but the files (exe or DLL) generated in this mode are usually large; generate
Mapfile, generate information about the. map file record module; Enable profiling, this parameter is usually
The mapfile parameter is used at the same time. If debugging information is generated, the. PDB file cannot be used and must be used.Microsoft
Format.

2) customize: You can set the database file. Force file output
To generate an output file (exe or DLL). Print progress messages can output the progress information during the connection to the output window.

3)
Debug: sets whether to generate debugging information and the format of debugging information. The formats include Microsoft format and coff format (Common Object File
Format) and both formats; Separate
Types: stores the debug format information in an independent. PDB file, or directly stores it in the. PDB file of each source file. If selected, the latter method is used. This method is faster for debugging and startup.

4)
Input: You can specify the library 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.

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 x0000000). When the operating system loads a program, it always tries to start from this base address. Entry-point
The entry address of a program can be specified by symbol. 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 uses winmaincrtstartup (or
Wwinmaincrtstartup) calls the winmain (or
Wwinmain, must use the _ stdcall call Convention); DLL uses the _ 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 (Please use decimal). The default value is 1 MB. Version
Information tells the connector to add the version number at the beginning of the EXE or DLL file.

It is worth noting that the above parameters are case-sensitive. Adding "-" after the parameter indicates that this parameter is invalid; parameter value options
"*" Indicates the default value of this parameter. You can use the "reset" button in the upper-right corner of the page to restore all default settings on this page.

Other parameter settings

1)
Project-> Settings-> General, you can set the method to connect to the MFC Library (static or dynamic ). For dynamic connection
Next, do not forget to bring the mfc dll when your software is released.

2)
Project-> Settings-> Debug: You can set executable files and command line parameters that run during debugging.

3)
Project-> Settings-> Custom
Build, you can set to automatically execute some operations after the compilation/connection is successful. Compared
If you want VC to automatically register the compiled COM file when writing COM, 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

4)
Tools-> options-> directories: Set the include and library paths of the system.

Tips

1)
Sometimes, during compilation, your 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. NCB,. Opt,. APs,. CLW files of the project and all files in the debug and release directories, and then recompile the files.
.

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 files and all files under the debug and release directories.

3)
When your workspace contains multiple projects, you may not be able to intuitively see which project is the current one. You can set tools> Options> Format as follows, and then select workspace in category.
Window to change its default font (for example, set it to fixedsys.

4)
How can I 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, delete the. CLW and. NCB items, re-open the project, click View> classwizard, and click "add" in the displayed dialog box.
"All" button; rebuild all again. The problem should be solved.

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.