Linux environment GNU, GCC, g++ compiler

Source: Internet
Author: User

One, GNU

GNU is the "GNU's not Unix" recursive abbreviation, Stallman announced that GNU should pronounce Guh-noo (slave) to avoid confusion with the word new (note: GNU in English is intended to be the African wildebeest, the same pronunciation as new)

In order to ensure that GNU software is free to "use, reproduce, modify and distribute", all GNU software is licensed under the terms of an agreement that authorizes all rights to anyone without the addition of any restrictions to any other person, the GNU General Public License (GNU LICENSE,GPL). This is known as the "anti-copyright" (or called copyleft) concept.

The gun can be understood as a Linux specification.

Second, the difference between GCC and g++

Both GCC and g++ are a compiler for the GNU (Organization). There are many misconceptions about their understanding:

"Misunderstanding one" GCC can only compile C code, g++ can only compile C + + code

Both are possible, but please note:
1. The suffix is. C, GCC treats it as a C program, and g++ as a C + + program; the suffix is. cpp, both of which are considered C + + programs, note that although C + + is a superset of C, there are different requirements for syntax, such as:

1 #include2 3 intMainintargcChar*argv[])4  5 {6  if(argv = =0)return;7 printstring (argv);8  return;9  Ten } One  A intPrintstring (Char*string)  -   - { thesprintfstring,"This is a test.\n"); -   -}

If you follow the grammar rules of C, OK, no problem, but once the suffix is changed to CPP, three errors are reported immediately: "Printstring undefined";
"Cannot convert ' char** ' to ' char*";
"Return-statement with no value";
Corresponds to the part of the previous red callout, respectively. Visual C + + syntax rules are more rigorous.

2. During the compile phase, g++ calls GCC, which is equivalent to C + + code, but because the GCC command is not automatically linked to the libraries used by C + + programs, it is usually done with g++ to complete the link, for the sake of unification, simply compile/link all with g++, which gives an illusion, As if the CPP program can only be used g++.

"Myth two": GCC does not define __cplusplus macros, and g++ will
In fact, this macro simply indicates that the compiler will interpret the code in C or C + + syntax, as described above, if the suffix is. c, and the GCC compiler is used, the macro is undefined, otherwise it is defined.

"Misunderstanding three": Compile only with GCC, link only with g++
Strictly speaking, this sentence is not wrong, but it confuses the concept, it should be said: Compile can be used gcc/g++, and links can be used g++ or gcc-lstdc++. Because GCC commands are not automatically joined to libraries that are used by C + + programs, you typically use g++ to complete joins. In the compilation phase, however, g++ automatically calls GCC, which is equivalent.

"Misunderstanding four": extern "C" is related to gcc/g++
In fact, no matter whether it is GCC or g++, with the extern "C", all are named in C to the symbol, otherwise, are named in C + +. The test is as follows:

1 me.h:2  extern "C" voidcppprintf (void);3  4 Me.cpp:5 #include6#include"me.h"7  using namespacestd;8  voidcppprintf (void)9  {Ten cout One #include A#include"me.h"  - intMainvoid) -  { the cppprintf (); -  return 0; -}



1. First add extern "C" to me.h, see what is different with GCC and g++ naming
[Email protected] g++]# g++-S Me.cpp
[email protected] g++]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the naming of this function
. Type cppprintf, @function
[Email protected] gcc]# gcc-s me.cpp
[email protected] gcc]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the naming of this function
. Type cppprintf, @function
Exactly the same!

2. Remove the extern "C" in the me.h to see what is different with GCC and g++ naming
[Email protected] gcc]# gcc-s me.cpp
[email protected] gcc]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the naming of this function
. Type _Z9CPPPRINTFV, @function
[Email protected] g++]# g++-S Me.cpp
[email protected] g++]# less ME.S
. GLOBL _Z9CPPPRINTFV//Note the naming of this function
. Type _Z9CPPPRINTFV, @function
Exactly the same!
It can be seen that extern "C" is not related to the use of gcc/g++, the above test also indirectly confirms the previous statement: in the compilation phase, g++ is called GCC.

Transferred from: http://www.linuxidc.com/Linux/2014-07/104299.htm

Linux environment GNU, GCC, g++ compiler (RPM)

Related Article

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.