When you write a C + +, how do you make it work? The specific steps depend on your computer environment and the C + + compiler you use, but it is broadly as follows:
1. Write the program using a text editor and save it to a file, which is the source code of the program.
2. Compile the source code. This means running a program that translates the source code into the internal language that the host is using-machine language. The file that contains the translated program is the object code of the program.
3. Strong target code is connected to other code. For example, C + + programs typically use libraries. The C + + library contains target code for a series of computer courses called functions that perform tasks such as displaying information on the screen or calculating the square root. A link is a combination of the target code of the target function of the target code with the function used and some standard startup code, which generates the runtime version of the program. The files that contain the final product are called executable code.
The procedures in this book are generic and can be run in any system that supports c++98, but the 18th chapter requires the system to support C++11. During the writing of this book, some compilers require you to use specific tags to support some of the c++11 features. For example, starting with version 4.3, g++ requires that you use the tag-std=c++0x when you mutate a source code file:
g++-std=c++0x Use_auto.cpp
Steps:
1. Create a source code file
Table 1.1 Extension of source code files
| C + + implementation |
Source code file suffix name |
| UNIX |
C, CC, CXX, c |
| GNU C + + |
C, CC, CXX, CPP, C + + |
| Digital Mars |
CPP, cxx | /tr>
| Borland C + + |
CPP |
tr>
| Watcom |
CPP |
| Microsoft Visual C + + |
CPP, CXX, CC |
tr>
| Freestyle Code Warrior |
CP, CPP, CC, CXX, C + + |
2. Compiling and linking
1.Unix Compiling and linking
......
2.Linux Compiling and linking
The most common compiler used in Linux is g++.
The following command generates the executable file a.out:
g++ Spiffy.cxx
Some versions may require links to C + + libraries:
g++ spiffy.cxx-lg++
To compile multiple source files, simply place them all on the command line:
g++ My.cxx Precious.cxx
This will generate a copy of the executable file named A.out and the two target code files my.o and PRECIOUS.O. If you subsequently modify one of the source code files, such as My.cxx, you can recompile using MY.CXX and PRECIOUS.O:
g++ My.cxx PRECIOUS.O
3.Windows command-line compiler
......
4.Windows compiler
......
C + + on 5.Macintosh
C + + Primer Plus Learning Note--c++ program creation to run the entire process