refer to NetEase blogger "Meditation" blog-"gcc and g++ differences" with their own understanding to make personal understanding. (Due to the limited personal level, there will inevitably be the wrong place, please forgive me)
in general, compiling a program under Linux is divided into the following 4 phases:
Preprocessing: Compiling macro commands such as handling macro definitions (eg: #define)--compiles a file with a suffix of ". I": converts preprocessed files into assembly language--a compilation of files with a suffix of ". S": Translations from assembly-generated files to binary target files-generating files with the suffix ". O" Connection: Multiple target files (binary) combined with library functions can be executed directly independently of the execution file--generate suffix to. out file under Linux performs gcc and g++ compile C + + files: The suffix is. c, and GCC treats it as a C program (Cc/cpp is judged c+ + source program, and g++ as a C + + program GCC cannot make a connection to the library file, that is, you cannot compile step 4, and g++ can completely compile the executable file. (Essentially, g++ from step 1-step 3 are called GCC complete, step 4 connection is done by themselves) the following simple test: test environment: CentOS 6.4 Test command: GCC-E execution to step 1, handle macro commands only, need to use redirected makefile Gcc-s execution to step 2. Generate file. s gcc-c execution to step 3, generate file. o g++ compiled separately from the connection. cc file with the. o File Test code:
#include <iostream>
using namespace std;
int main ()
{
cout<< "This is a C + + program." <<endl;
}
Test results:
GCC-E 1.cc >> 1.i
VI 1.i
Gcc-s 1.cc
VI 1.s
Gcc-c 1.cc
Next Test the results of g++ 1.O and direct g++ 1.cc:
g++ 1.o-o From_o
Run Result:
g++ 1.cc-o FROM_CC
Run Result:
If you compile a linked C + + file directly with GCC, there will be an error, because you cannot link.
GCC 1.cc