What is the difference between g++ and gcc? Which ones should be used for general c++ development?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
GCC: GNU Compiler Collection
gcc: GNU C Compiler
g++: GNU C++ Compiler
The main differences:
Extra Macros when compiling *.cpp files:
I was testing gcc and g++ in a linux system. By using MAKEFILE, I can define the compliler used by "GNU make". I tested with the so called "dynamic memory" locating feature of "C plus plus" by :
Only g++ can successfully compile on my computer while gcc will report error
So my own conclusion is gcc does not fully support "C plus plus". It seems that choosing g++ for C++ source files is a better option.
gcc
andg++
are compiler-drivers of the GNU Compiler Collection (which was once upon a time just the GNU C Compiler).Even though they automatically determine which backends (
cc1
cc1plus
...) to call depending on the file-type, unless overridden with-x language
, they have some differences.The probably most important difference in their defaults is which libraries they link against automatically.
According to GCC's online documentation link options and how g++ is invoked,
g++
is equivalent togcc -xc++ -lstdc++ -shared-libgcc
(the 1st is a compiler option, the 2nd two are linker options). This can be checked by running both with the-v
option (it displays the backend toolchain commands being run).I became interested in the issue and perform some experiments
I found that description here, but it is very short.
Then I tried to experiment with gcc.exe and g++.exe on my windows machine:
I tried to compile c89, c99, and c++1998 simple test files and It's work well for me with correct extensions matching for language
But when I try to run "gnu compiler collection" tool in that fashion:
But this one still work with no errors
And this also
p.s. Test files
Findings:
If look at process tree then it seems that gcc, and g++ is backend to other tools, which in my environment are: cc1plus.exe, cc1.exe, collect2.exe, as.exe, ld.exe
gcc works fine as metatool for if you have correct extension or set correct -std -x flags. See this
“GCC” is a common shorthand term for the GNU Compiler Collection. This is both the most general name for the compiler, and the name used when the emphasis is on compiling C programs (as the abbreviation formerly stood for “GNU C Compiler”).
When referring to C++ compilation, it is usual to call the compiler “G++”. Since there is only one compiler, it is also accurate to call it “GCC” no matter what the language context; however, the term “G++” is more useful when the emphasis is on compiling C++ programs.
You could read more here.
What is the difference between
g++
andgcc
?gcc
has evolved from a single language "GNU C Compiler" to be a multi-language "GNU Compiler Collection". The term "GNU C Compiler" is still used sometimes in the context of C programming.The
g++
is the C++ compiler for the GNU Compiler Collection. Likegnat
is the Ada compiler forgcc
. see Using the GNU Compiler Collection (GCC)For example, the Ubuntu 16.04 and 18.04
man g++
command returns theGCC(1)
manual page.The Ubuntu 16.04 and 18.04
man gcc
states that ...and that the default ...
Search the
gcc
man pages for mores particulars on the option variances ofgcc
andg++
.Which one should be used for general c++ development?
Technically, either
gcc
org++
can be used for general C++ development with applicable option settings. However, theg++
default behavior is naturally aligned to a C++ development.The Ubuntu 18.04 man page added the following paragraph: