Console Write Program

Source: Internet
Author: User

I have used more than N ide tools, but I still don't know how to coordinate IDE and compile the Connection Program. Below I will do a little research and write a program on the console. For example, when Visual Studio compiles a C ++ program, we will see the entire compilation and connection process in the output window below the IDE, although we cannot see the pop-up DOS window, but in fact, IDE has successively started the Microsoft csf-‑compiler cl.exeand connector link.exe, and the output of cl.exeand link.exe is reflected in the IDE output window in real time. With a real understanding of the operating mechanism of IDE, we can do a lot of things, huh, and even write the IDE interface by ourselves. Slickedit is such a tool. It supports n languages.

1. Set environment variables for C/C ++

In the early days, the C compiler on PC needs 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.
Until now, the C/C ++ compiler needs these three environment variables.

You can write a batch as follows:

Set Path = C:/msdev/vc98/bin; C:/msdev/common/msdev98/bin
Set include = C:/msdev/vc98/include
Set Lib = C:/msdev/vc98/lib

The reason for setting Path = C:/msdev/common/msdev98/bin is that the compiler Cl. mspdb60.dll is required for EXE execution, and it is installed with C:/msdev/common/msdev98/bin.

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

Set Path = C:/msdev/vc98/bin; C:/msdev/common/msdev98/bin
Set include = C:/msdev/vc98/include; C:/msdev/vc98/mfc/include
Set Lib = C:/msdev/vc98/LIB; C:/msdev/vc98/mfc/lib

If you specify MFC/include and MFC/lib, the compiler and the connector can find the header files and libraries of MFC. If you still need to Use ATL, you must add C:/msdev/vc98/ATL/include to the include environment variable.

Of course, you can execute the VC directory and your vcvars32.bat, which saves a lot of trouble.

2. How to compile C/C ++ programs

Enter the DOS interface, Type

> Cl test. cpp <enter>

You can compile and connect. Note that the/C option is omitted in cl, And the link connection program is automatically called.

Complete Compilation. The connection process is:

CL/C test. cpp <enter>

Link test. OBJ ***** (*** is necessary for libraries)

For multiple files, it is best to write makefile and then run it with nmake in VC.

 

Note:

That is to say, most ide tools can call specific command line programs in the Integration Environment (console programs in Win32 ), then, they capture their output in real time (most of which are output to the standard stdout and stderr streams) and display the captured information in the graphic interface window.

This is obviously a feature with potential value. With this technology, we can at least

1. compile your own IDE, if we have enough patience;

2. embed full-text retrieval in our own applications (call Borland functions, etc );

3. connect to a console program compiled by others or a console program we wrote a long time ago-I am often troubled by the difficulty of calling a console program with powerful functions but no source code.

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.