Related file suffixes in C + + programming
A static library (archive). C + +
. C
. cc
. CP
. cpp
. cxx
. C++c++ Source code (requires compilation preprocessing). HC or C + + source generation dock files. Iic++ source code (without compilation preprocessing). O Object file. S assembly code. So dynamic Library <none> standard C + + system header file
A single source file generates an executable program
Here is a simple C + + program code saved in file Helloworld.cpp:
/* Helloworld.cpp *
#include <iostream>
int main (int argc,char *argv[])
{
&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP; Std::cout << "Hello, World" << Std::endl;
return (0);
}
The program uses the cout defined in the header file iostream to write a simple string to the standard output. The code can be compiled into an executable file with the following command:
$ g++ Helloworld.cpp
Compiler g++ can be recognized as a C + + source code file by checking the suffix name of the file specified on the command line. Compiler default action: Compile source code file to generate object file, link object file and function in Libstdc++ Library to get executable program. The object file is then deleted. The compiler takes the default a.out because the file name of the executable program is not specified on the command line. Programs can run like this:
$/a.out
Hello, world
It is more common to specify the file name of an executable program by using the-o option. The following command produces an executable file named Hello:
$ g++ Helloworld.cpp-o Hello
Enter the program name on the command line to run:
$/helloworld
Hello, world
Program g++ is to set the GCC default language to a special version of C + +, which automatically uses the C + + standard library instead of the C standard library. By following the naming conventions of the source code and specifying the name of the corresponding library, it is possible to compile the linked C + + program with GCC, as shown in the following example:
$ gcc helloworld.cpp-lstdc++-o Hello
Option-L (ELL) by adding prefix lib and suffix. A transforms the name following it into the library's name LIBSTDC++.A. It then looks for the library in the standard library path. The compilation process and output file for GCC are identical to the g++.
In most systems, GCC installs a program that is C + +. If it is installed, it is equivalent to g++, as shown in the following example, and the usage is consistent:
$ c + + Helloworld.cpp-o Hello