GNU, GCC, G ++ compiler in Linux
1. GNU
GNU is the abbreviation of "GNU's Not Unix". Stallman announced that GNU should be pronounced as Guh-NOO to avoid confusion with the word "new" (note: in English, Gnu stands for the African Impala. Its pronunciation is the same as that of new)
To ensure that the GNU software can be freely used, copied, modified, and released ", all GNU software grants all rights to anyone in a copy of the terms of the agreement, GNU General Public License (GPL), which prohibits others from adding any restrictions ). This is the concept of "anti-copyright" (or Copyleft.
GUN can be understood as a linux specification.
2. Differences between gcc and g ++
Both gcc and g ++ are GNU compilers. There are many misunderstandings about them:
[Misunderstanding 1] gcc can only compile c code, 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. For example:
# Include
Int main (int argc, char * argv [])
{
If (argv = 0) return;
PrintString (argv );
Return;
}
Int printString (char * string)
{
Sprintf (string, "This is a test. \ n ");
}
If it is OK according to the C syntax, but once the suffix is changed to cpp, three errors are immediately reported: "printString undefined ";
"Cannot convert 'Char ** 'to 'Char *";
"Return-statement with no value";
Corresponding to the red part. It can be seen that the syntax rules of C ++ are more rigorous.
2. in the compilation phase, g ++ calls gcc. For c ++ code, the two are equivalent, but because the gcc command 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 compiling, and g ++ can be used for linking.
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.
[Misunderstanding 4]: extern "C" is related to gcc/g ++.
In fact, it does not matter. Whether it is gcc or g ++, when using extern "c", it is named as C. Otherwise, all are named in c ++ mode. The test is as follows:
Me. h:
Extern "C" void CppPrintf (void );
Me. cpp:
# Include
# Include "me. h"
Using namespace std;
Void CppPrintf (void)
{
Cout
# Include
# Include "me. h"
Int main (void)
{
CppPrintf ();
Return 0;
}
1. Add extern "C" to me. h to see if the names of gcc and g ++ are different.
[Root @ root G ++] # g ++-S me. cpp
[Root @ root G ++] # less me. s
. Globl _ Z9CppPrintfv // note the name of this function
. Type CppPrintf, @ function
[Root @ root GCC] # gcc-S me. cpp
[Root @ root GCC] # less me. s
. Globl _ Z9CppPrintfv // note the name of this function
. Type CppPrintf, @ function
Identical!
2. Remove extern "C" from me. h to see if the gcc and g ++ naming are different.
[Root @ root GCC] # gcc-S me. cpp
[Root @ root GCC] # less me. s
. Globl _ Z9CppPrintfv // note the name of this function
. Type _ Z9CppPrintfv, @ function
[Root @ root G ++] # g ++-S me. cpp
[Root @ root G ++] # less me. s
. Globl _ Z9CppPrintfv // note the name of this function
. Type _ Z9CppPrintfv, @ function
Identical!
It can be seen that extern "C" has nothing to do with the use of gcc/g ++. the above tests indirectly confirm the previous statement: In the compilation phase, g ++ calls gcc.