The difference between GCC and g++

Source: Internet
Author: User

First describe the error you encountered today:

Because before writing the program, write is CPP file, and then directly use g++ compile, no error, also did not care about these problems, today there is a C file, but contains after the STL vector syntax, think of using GCC to compile, the result error, error is: Can't find the vector.

What is gcc/g++

First of all: GCC and GCC are two different things

Gcc:gnu Compiler Collection (GUN compiler Collection), it can compile C, C + +, JAV, Fortran, Pascal, Object-c, Ada and other languages.

GCC is the gun C Compiler (C compiler) in GCC

G++ is the gun C + + Compiler (c + + compiler) in GCC

An interesting fact is that, in essence, GCC and g++ are not compilers, nor are they collections of compilers, they are just a kind of drive, depending on the type of file to be compiled in the parameter, call the corresponding gun compiler, for example, to compile a C file with GCC, there are several steps:

Step1:call a preprocessor, like CPP.

Step2:call an actual compiler, like CC or CC1.

Step3:call an assembler, like as.

Step4:call a linker, like LD

Because the compiler can be replaced, GCC can not only compile C files

So, more accurately, GCC calls C compiler, and g++ calls C + + compiler

The main differences between GCC and g++

1. For *.c and *.cpp files, GCC is compiled as C and CPP files respectively (c and CPP are not the same syntax strength)

2. For *.c and *.cpp files, g++ is unified as CPP file compilation

3. When compiling files using g++,g++ automatically links the standard library STL, and GCC does not automatically link the STL

4. GCC when compiling c file, can use the predetermined macros is relatively few

5. When compiling CPP files, gcc/g++ when compiling C files and CPP files (when both GCC and g++ invoke the CPP file compiler), some additional macros are added as follows:

#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __exceptions 1
#define __PRIVATE_EXTERN__ extern

6. When compiling C + + files with gcc, it is necessary to add parameter –lstdc++ in order to be able to use STL , but this does not mean that gcc–lstdc++ and g++ are equivalent, they are not only the difference between this

Main parameters

-g-turn on debugging (so GDB gives morefriendly output)

-wall-turns on most warnings

-O Or-o2-turn on optimizations

-o-name of the output file

-c-output an Object file (. O)

-i-specify an Includedirectory

-l-specify a Libdirectory

-l-link with LIBRARYLIB.A

Use example: g++-ohelloworld-i/homes/me/randomplace/include HelloWorld. C

The difference between GCC and g++

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.