Use a C / C compiler in Console Mode
Houjie 1999.04.08
I always encourage C / C learners. When I just exposed to this program, I will first take the console mode (dos-like) program. In other words, don't write the GUI program at the beginning, want to open the window, want to have a glamorous picture - that is just not going to fly, and the seedlings will help. The so-called console program is the program of the text mode. We can practice the language of C / C language, without distracting, without distinctiveness. I have always thought that this is a matter of course, but I have been discovered that there are many C / C courses in many colleges and universities. The students must write a small work, little painter, and small abacus. Sure enough, the world is not big, each person's opinion is special :) I not only think that the C / C program development object should be mainly console mode, I also believe that C / C program development environment, in the early days, the main stage is mainly mainly. In other words, don't enter the integration environment (IDE) at the beginning. So many windows in the integration environment, so many features, so many preset values, will make program novice eye, unable to master some valuable knowledge and experience in the program compilation process. Waiting for our minimum understanding of the compiler, then use the integrated environment, I think this is best. So, whether in
● Take Visual C as an example for Visual C , if the installed file layout is as follows: c: / msdev / vc98 / bin: here is placed here CL.EXEC: / MSDEV / VC98 / include: here C / C header filesc: / msdev / vc98 / lib: There is a C / C Standard Libraries. So you can write a batch file as follows: set path = c: / msdev / vc98 / bin; c: / msdev / common / msdev98 / Binset include = c: / msdev / vc98 / includeSet lib = c: / msdev / vc98 / lib why need to be added PATH = C: / msdev / common / msdev98 / bin because the compiler CL.EXE is required Mspdb60.dll, and it is installed in C: / MSDEV / COMMON / MSDEV98 / BIN. If you write the program is not just a simple C / C program, it also uses the MFC, which can be compiled under console mode, this time your environment variable should be so setting: set path = C: / MSDEV / VC98 / BIN; C: / msdev / common / msdev98 / binset incrude = C: / msdev / vc98 / include; c: / msdev / vc98 / mfc / incruDeset lib = C: / MSDEV / VC98 / LIB; C: / MSDEV / VC98 / MFC / LIB multi-specified MFC / Include and MFC / LIB, allows compilers and couplers to find MFC's Header Files and Libraries. If you need to use ATL, you have to add C: / MSDEV / VC98 / ATL / include in the include environment variable. ● Take Borland C Builder as an example of Borland C Builder, if the installation of the file is released as follows: c: / borland / cbuilder3 / bin: This is a compiler BCC32.exec: / borland / cbuilder3 / include : There is a C / C header filesc: / borland / cbuilder3 / lib: there is a C / C Standard Libraries. So you can write a batch file as follows: set path = c: / borland / cbuilder3 / binset incrude = C: / Borland / cbuilder3 / includeSet lib = c: / borland / cbuilder3 / lib ● How to compile C / C programs in Console First, turn on a DOS Box (DOS PROMPT, DOS VM), then perform the above write in this DOS BOX Batch file, complete the setting of environmental variables. You can type the set command in the DOS prompt number to see if the setting content of the environment variable is correct or not. Then you can type the compiler name directly under the DOS prompt number and start compiling. If you use Visual C , do this: C: /> CL Test.cpp
All compile options can be seen as long as CL / or BCC32 (without any quotes will be added). ● The compiler with the association process is separated from the coupling process. In other words, we must do two actions: C: /> CL Test.cppc: /> link test.obj xxx (xxx represents each necessary libraries) or: c: /> bcc32 test.cppc: /> TLINK32 TEST .Obj xxx (xxx represents each necessary libraries) Today's compilation process is of course separate, but our actions require only one: c: /> CL Test.cpp or: c: /> bcc32 test.cpp This is because the compiler is smart unless you specify / c option (indicating that only the compilation does not connect), otherwise it will automatically connect the coupon. In the past, the problem of "which Libraries" that made Programmer's troubles has also been a smart solution: it records the library functions used in the program, and also records the Library names they belong, so the coupon You can know which Libraries you want to link from this form. ● Environmental variables and DOS VM (Virtual Machine). You can start multiple DOS BOX simultaneously, but you cannot perform the above-mentioned batch files in a DOS box and enjoy its environment settings in another DOS VM. This is because each DOS Box is a Virtual Machine, who can't see each other, nothing to do. Unless you set these environment variables described above unless you are in AutoExec.bat. In this way, any newly opened DOS VM will inherit the variable settings because of the most primitive DOS VM environment. ● Environment Space is not the most difficult, which is the problem of indignment space. When you install Visual C , you will find a file called vcvars32.bat in its bin subdirectory. This file is actually the above environment variable setting action (this is explained in the last step in the Visual C installation process. Hey, how many people install the software do not explain!). So, you can execute this file in any DOS box, replace the aforementioned our own batch file. But usually have a failure experience to get the "Out of Environment Space" error message. This is because vcvars32.bat uses the following syntax: set include =% msvcdir% / ATL / include;% msvcdir% / include;% msvcdir% / mfc / include;% include% set lib =% msvcdir% / lib;% msvcdir% / Mfc / lib;% lib% means additional settings for the original setting of the include, and add other settings to the original setting (% lib%) of the LIB. If the original setting is very long, more comment several times, "Out of Environment Space"! One of the practices is to increase the size of the environment.