Use CC ++ compiler in Console mode

Source: Internet
Author: User

Use CC ++ compiler in Console mode

--------------------------------------------------------------------------------

I always encourage CC ++ learners to first target the Console mode (DOS-like) program when they are new to this programming language. In other words, you don't want to write GUI programs, open windows, and have a dazzling screen at the beginning-it's just not going to fly first.

The so-called console program is a text-mode program. In this program, we can train the language of CC ++ well without being distracted by other unnecessary guis.

I always thought that this was a matter of course, but I still found that many colleges and universities have large CC ++ courses, students must write a small writer, painter, and Abacus as their mid-term or final assignments.

Sure enough, the world cannot be the same, and everyone's views are quite different)

I not only think that the initial stage of the CC ++ program development object should be dominated by Console mode, but also think that the initial stage of the CC ++ program development environment should also be dominated by Console mode. In other words, do not start with the integrated environment (IDE ). The integration of so many windows, so many functions, and so many preset values in the environment will make new programmers confused and fail to master some valuable knowledge and experience during program compilation.

When we have a minimum understanding of the Compilation Program, and then use the integrated environment, I think this is the best.

Therefore, I will briefly describe the job methods in the Console mode in simple introduction to MFC or multi-type and virtual books. For more information, see "MFC" in p.m. and "multi-type and virtual" in p.233.

However, I still occasionally receive questions from netizens (whether or not I have read two books), asking about how to compile the Console mode, or asking them about the problems they encountered.

I will sort out this question again. Then, I can mail the whole question to the questioner.

★★Note: The following are suitable for PC environments:★★

● CC ++ compiler environment variable settings

In the early days, the C compiler on PC requires two environment variables:

Lib: This environment variable tells the compiler where libraries is necessary (under which disk directory)
Include: Tell the compiler where the necessary header files are (under which disk directory)

In addition, in order for us to get the compiler in any working directory, we must set the path.

From the beginning to the present, the CC ++ compiler needs these three environment variables.

● Take Visual C ++ as an Example

Take visual c ++ as an example. If the file layout after installation is as follows:

Cmsdevvc98bin contains the compiler Cl. EXE.
Cmsdevvc98include contains CC ++ header files.
Cmsdevvc98lib has cc ++ standard libraries.

You can write a batch file as follows:

Set Path = cmsdevvc98bin; cmsdevcommonmsdev98bin
Set include = cmsdevvc98include
Set Lib = cmsdevvc98lib

You need to set Path = cmsdevcommonmsdev98bin because the mspdb60.dll is required for the Cl. EXE compiler for execution and is installed in cmsdevcommonmsdev98bin.

If the program you write is not just a CC ++ program, but also an MFC program, you can compile it in Console mode. At this time, your environment variable should be set as follows:

Set Path = cmsdevvc98bin; cmsdevcommonmsdev98bin
Set include = cmsdevvc98include; cmsdevvc98mfcinclude
Set Lib = cmsdevvc98lib; cmsdevvc98mfclib

If mfcinclude and mfclib are specified, the compiler and the connector can find the MFC header files and libraries. If you still need to Use ATL, you need to add cmsdevvc98atlinclude to the include environment variable.

● Taking Borland C ++ Builder as an Example

Taking Borland C ++ Builder as an example, if the file layout after installation is as follows:

Cborlandcbuilder3bin contains the compiler bcc32.exe.
Cborlandcbuilder3include contains CC ++ header files.
Cborlandcbuilder3lib has cc ++ standard libraries.

You can write a batch file as follows:

Set Path = cborlandcbuilder3bin
Set include = cborlandcbuilder3include
Set Lib = cborlandcbuilder3lib

● How to compile CC ++ programs in the console

First, enable a DOS box (DOS prompt, dos vm), and then execute the preceding batch files in the DOS box to complete environment variable settings. You can enter the set command in the DOS prompt to check whether the environment variable settings are correct.

Then you can directly enter the name of the compiler under the DOS prompt to start compilation. If you use visual c ++, do this:

C Cl test. cpp enter

If you use C ++ builder, do this:

C bcc32 test. cpp enter

In special cases, you must check the special options. You can view all compile options by executing Cl or bcc32 without any reference.

● Relationship between the compiler and the connector

The early compilation process is separated from the join process. In other words, we must do two actions:

C Cl test. cpp
C link test. obj xxx (xxx represents all necessary libraries)

Or:

C bcc32 test. cpp
C tlink32 test. obj xxx (xxx represents all necessary libraries)

Today's compilation process and linking process are of course separate, but we only need one action:

C Cl test. cpp

Or:

C bcc32 test. cpp

This is because the compiler becomes smarter. Unless you specify C option (indicating that only compilation is not associated), it automatically calls the connector for you. The question about which libraries to use has plagued programmer in the past. The Compiler also has a smart solution: it records the library functions used in the program, the name of the library to which they belong is also recorded, so that the connector can know which libraries to be joined from this table.

● Relationship between environment variables and dos vm (Virtual Machine)

You can enable multiple DoS boxes at the same time, but you cannot execute the above batches in a DOS box and enjoy the environment settings in another DoS VM.

This is because every DOS box is a virtual machine, and no one can see each other.

Unless you have set these environment variables in autoexec. bat. In this case, any newly opened dos VM inherits the original dos VM environment and inherits the variable settings.

● Insufficient Environment Space

One of the most common problems is the lack of environment space.

After visual c ++ is installed, a file named vcvars32.bat is found in its bin subdirectory. This file is actually used to set the environment variables (this is described in the last step of the Visual C ++ installation process. Ah, don't read the instructions for installing software for many people !). Therefore, you can execute this file in any DOS box to replace our own batch file.

However, we usually have failed experiences and get the error message of out of environment space. This is because vcvars32.bat uses the following syntax:

Set include = % msvcdir % atlinclude; % msvcdir % include; % msvcdir % mfcinclude; % include %
Set Lib = % msvcdir % LIB; % msvcdir % mfclib; % lib %

This means that the original include settings (% include %) are appended with other settings, and the original lib settings (% lib %) are appended with other settings. If the original setting has been very long, so many times, it will be out of the Environment Space!

One way is to increase the size of the Environment Space. Please add this line in the cconfig. SYS file:

Shell = ccommand. com C e1024 P

E1024 indicates that the environment space is adjusted to 1024 bytes. (Not enough? Re-tune)

The second practice is not to use the "additional" pattern of vcvars32.bat. Instead, use our own batch file. You know, we may have several compiler environments (VC, BCB, G ++ compiler), and we need to test our program in turn. If we use the "additional" sentence pattern, we will try it several times, even a large environment space will be exhausted.

Both method 1 and method 2 must be implemented.

● Is there any scale limit?

Can I use the Console mode (or command line mode) to compile a program? Is there any size limit on the program size? The answer is no!

Its disadvantage is that there is no tool to help you manage your files, there is no preset value for you to play a few words less, there is no analysis tool to help you organize objects, let you browse objects, symbols volumes. So once you have learned the basic skills, it is better to start designing medium and large programs by integrating the environment (IDE.

● Do not misunderstand

I am not reversing the game. I want everyone to go back to the age of Ru Mao drinking blood and be the best man. However, I think that the application of integrated environment (IDE) for a CC ++ beginner may be confusing. It is better to first work in Console mode. On the one hand, I have a good understanding of some common environment settings. On the one hand, it is more convenient and easy to use, and I don't have to write a 1000-line small exercise. I have to start the native cannon, on the one hand, the power of knowledge can all be put on Language exercises.

If the integrated environment is used to a certain extent, it will not fall into the fog.

-- The end

 

This article is from the csdn blog. For more information, see httpblog. csdn. netklinsmenarchive200611221405300.aspx.

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.