"description" reproduced in this article from the meditation article http://blog.163.com/lu_jun520/blog/static/5699613420116205148239/
The general Linux system comes with the GCC compiler, you can use your installation CD to install, if you feel that the GCC version is too low, you can go to the official GCC website can be downloaded to, the compilation takes a long time, if you only compile C or C + + can download only gcc-g++ And Gcc-core, so the compilation may be faster, at night before bedtime, you can compile, in the morning can be compiled, I generally do so. However, the premise of this installation is that you have the GCC compiler on Linux, gcc-g++ and Gcc-core simultaneously decompression, and then execute configure to take parameters, mainly set your machine type and installation path, the execution of the time you see with the Configure- Help to see the specific parameters, mainly to set the installation path that parameter--prefix executed successfully generated the makefile file (configure--prefix=/usr/local/gcc-4.2.4- Disable-checking--host=i386-redhat-linux),
Then it's the long make, and when you're done, do install and install, and set the LD_LIBRARY_PATH environment variable ld_library_path=/usr/local/gcc-4.2.4/lib:$ Ld_library_path.
My is gcc3.3 later installed gcc4.2, the original/usr/bin below the gcc,g++ respectively renamed to gcc3.3,g++3.3,
Then the usr/local/gcc-4.2.4/bin/under the GCC and g++ built a connection to the usr/bin/, so that when we compile with GCC or g++ is the new version of the compiler, if you want to use the old versions of gcc3.3 or g++3.3
Http://www.gnu.org/prep
Linux installation Gcc/gcc-c++/g++/gdb
#安装安装gcc编译器 (c program can be compiled)
Yum Install GCC
#安装g + + (can compile C + + programs after installation)
Yum Install gcc gcc-c++
#安装gdb (Debug tool gdb)
Yum Install GDB
GCC and g++ are GNU C & C + + compilers, respectively
gcc/g++ a total of 4 steps in the process of compiling
1. Preprocessing, generating. I files [preprocessor CPP]
2. Convert the preprocessed file into assembly language and generate the file. s[compiler Egcs]
3. From assembly to target code (machine code) generate. o file [assembler as]
4. Connect the target code, generate the executable program [linker LD]
The difference between GCC and g++
Both GCC and g++ are a compiler for the GNU (Organization).
Myth 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 is a difference between the two requirements for syntax. 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.
Myth 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.
The difference between GCC and g++
When we compiled C + + code, some people use GCC, some people use g++, so all kinds of statements come, such as C code with GCC, and C + + code with g++, or compiled with GCC, link with g++, for a moment I do not know which statement is correct, if you encounter the last extern "C", There are more differences, and here I want to finish, after all, the purpose of knowledge is to be more sober, not more confused.
Myth 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:
#include <stdio.h>
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 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.
Myth 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.
Myth four: extern "C" has relation with 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:
Me.h:
extern "C" void cppprintf (void);
Me.cpp:
#include <iostream>
#include "me.h"
using namespace Std;
void cppprintf (void)
{
cout << "hello\n";
}
Test.cpp:
#include <stdlib.h>
#include <stdio.h>
#include "me.h"
int main (void)
{
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!
"Reprint" The difference between GCC and g++