The difference between GCC and g++ under Linux __linux

Source: Internet
Author: User
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


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.