Different compilers: The difference between GCCG ++ CC ++
Source: Internet
Author: User
Different compilers: The difference between GCCG ++ CC ++-general Linux technology-Linux programming and kernel information. For more information, see the following. Gcc is the c compiler and g ++ is the c ++ compiler. Cc is generally a symbolic connection that points to gcc. CC is generally a name in makefile. The specific name is determined based on the actual situation.
Both gcc and g ++ are GNU compilers.
Misunderstanding 1: gcc can only compile c code, while g ++ can only compile c ++ code
Both can be used, but note the following:
1. Suffix. c, gcc treats it as a C program, while g ++ treats it as a c ++ program; suffix. cpp, both of which are considered as c ++ programs. Note that although c ++ is a superset of c, their syntax requirements are different. C ++ syntax rules are more rigorous.
2. In the compilation phase, g ++ calls gcc. For c ++ code, the two are equivalent. However, because gcc commands cannot be automatically connected to the library used by the C ++ program, therefore, we usually use g ++ to complete the link. For the sake of unification, we simply use g ++ to compile/link all. This gives us the illusion that, it seems that cpp programs can only use g ++.
Misunderstanding 2: gcc does not define the _ cplusplus macro, while g ++ will
In fact, this macro only indicates that the compiler will interpret the code in the C or C ++ syntax. As mentioned above, if the suffix is. c. If the gcc compiler is used, the macro is undefined. Otherwise, the macro is defined.
Misunderstanding 3: only gcc can be used for compilation, and only g ++ can be used for Link
Strictly speaking, this sentence is not a mistake, but it obfuscated the concept. It should be said that gcc/g ++ can be used for compilation, the link can use g ++ or gcc-lstdc ++. Because the gcc command cannot be automatically connected to the library used by the C ++ program, g ++ is usually used to complete the connection. However, in the compilation phase, g ++ automatically calls gcc, which is equivalent to the two.
What are the essential differences between CC cc gcc g ++?
Traditionally, unix OS is equipped with C compiler by default. Generally, the symbolic name cc is used, and C ++ compiler needs to be purchased separately.
In almost all cases, C/C ++ compiler is only the front end driver. the following compilers are the same. for example, gcc and g ++ provide different options for the compiler and link editor. these include user options, default options, and corresponding default system library. each compiler has a configuratoin file to specify these default options. use verbose mode (-v) to view the content.
Because of the syntax (namespace, class, overload...) of the C ++ program, you need to use extern "C" when linking all symbol names of mangle with C Programs ".
C ++ compiler can certainly compile C code. Note that apart from C ++'s syntax extension to C, the standard libraries for compiling and linking C and C ++ are usually different. I used gcc instead of g ++ to compile the C ++ program to prove this point.
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