G++有什么区别和GCC?
G ++和GCC有什么区别?其中哪一个应用于一般C ++开发?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
G ++和GCC有什么区别?其中哪一个应用于一般C ++开发?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(11)
GCC
和g ++
是GNU编译器 Collection 的编译器驱动程序(曾经是GNU c编译器)。即使他们自动确定哪些后端(
cc1
cc1plus
...)以根据文件类型来调用,除非用>
,他们有一些差异。> x语言
他们默认值最重要的区别是它们会自动链接到哪些库。
根据GCC的在线文档链接选项和如何调用g ++ ,
g ++
等效于GCC -XC ++ -LSTDC ++ -SHARED -LIBGCC
(第一个是编译器选项,第二个两个是链接器选项)。可以通过使用-V
选项运行(它显示正在运行的后端工具链命令)来检查这。默认情况下(和
GCC
不同), g ++还添加了链接选项-lm
- 以libm
链接,其中包含Math.h的实现
。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 roughly 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).By default (and unlike
gcc
), g++ also adds linker option-lm
-- to link againstlibm
which contains implementations formath.h
.GCC:GNU编译器集合
GCC
:GNU C       编译器G ++
:GNU C ++编译器主要区别:
GCC
将编译:*。c \*。cpp
cpp 分别为c和c ++ 。g ++
将编译:*。c \*。cpp
文件,但它们都将被视为C ++文件。g ++
链接它自动在STD C ++库中链接的对象文件(GCC
不执行此操作)。GCC
编译C文件的预定义宏更少。GCC
编译*。cpp
和g ++
编译*。c \*。cpp
文件具有一些额外的宏。编译
*。cpp
文件时的额外宏:GCC: GNU Compiler Collection
gcc
: GNU C Compilerg++
: GNU C++ CompilerThe main differences:
gcc
will compile:*.c\*.cpp
files as C and C++ respectively.g++
will compile:*.c\*.cpp
files but they will all be treated as C++ files.g++
to link the object files it automatically links in the std C++ libraries (gcc
does not do this).gcc
compiling C files has fewer predefined macros.gcc
compiling*.cpp
andg++
compiling*.c\*.cpp
files has a few extra macros.Extra Macros when compiling
*.cpp
files:对于C ++,您应该使用G ++。
它是相同的编译器(例如GNU编译器集合)。 GCC或G ++只需选择具有不同默认选项的不同前端。
简而言之:如果您使用G ++,前端将告诉链接器您可能需要与C ++标准库链接。 GCC前端不会这样做(如果您通过正确的命令行选项,它也可以与它们链接)。
For c++ you should use g++.
It's the same compiler (e.g. the GNU compiler collection). GCC or G++ just choose a different front-end with different default options.
In a nutshell: if you use g++ the frontend will tell the linker that you may want to link with the C++ standard libraries. The gcc frontend won't do that (also it could link with them if you pass the right command line options).
之间有什么区别
g ++
和gcc
?gcc
成为多语言“ GNU编译器集合”。术语GCC
有时仍会在C编程的上下文中引用“ GNU C编译器”。但是, /a>
g ++
是 GNU编译器集合的C ++编译器前端。像gnat
是gcc
的ADA编译器前端。 请参阅使用GNU Compiler Collection(GCC)例如,ubuntu 16.04和18.04
man g ++
命令返回gcc(1)
手动页面。Ubuntu 16.04和18.04
MAN GCC
指出...g ++
主要接受与gcc
和默认值搜索
GCC
MAN页面以获取有关GCC
和g ++
之间选项差异的更多详细信息。从技术上讲,应该将哪个用于一般C ++开发?
,
gcc
或g ++
可以用于带有适用选项设置的常规C ++开发。但是,g ++
默认行为自然与C ++开发一致。ubuntu 20.04 … ubuntu 24.04 继续有以下段落:
。 > g ++ 只需链接到
gcc
。 因此,g ++
调用可能会在每个脚链的基础上有所不同。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 termgcc
may still sometimes refer to the "GNU C Compiler" in the context of C programming.However,
g++
is the C++ compiler frontend for the GNU Compiler Collection. Likegnat
is the Ada compiler frontend 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 more details on the option variances betweengcc
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 'gcc' man page added, and Ubuntu 20.04 … Ubuntu 24.04 continue to have, the following paragraph:
Side Note: In the case of the Xcode.app toolchain,
g++
simply links togcc
. Thus,g++
invocations may vary on a per-toolchain basis.一个值得注意的区别是,如果您将
.c
文件传递给GCC,则将编译为C。G++的默认行为是将
.c .c
文件视为C ++(除非<<<<<指定代码> -x c )。One notable difference is that if you pass a
.c
file to gcc it will compile as C.The default behavior of g++ is to treat
.c
files as C++ (unless-x c
is specified).尽管GCC和G ++命令做非常相似的事情,但G ++设计为您调用以编译C ++程序的命令。它旨在自动做正确的事情。
在幕后,它们确实是相同的程序。据我了解,两者都根据文件扩展决定是否将程序编译为C还是C ++。两者都可以链接到C ++标准库,但默认情况下只有G ++才能进行。因此,如果您有一个在C ++中编写的程序,而该程序恰好需要与标准库链接,那么GCC将碰巧做正确的事情。但是,G ++也会。因此,确实没有理由不将G ++用于一般C ++开发。
Although the gcc and g++ commands do very similar things, g++ is designed to be the command you'd invoke to compile a C++ program; it's intended to automatically do the right thing.
Behind the scenes, they're really the same program. As I understand, both decide whether to compile a program as C or as C++ based on the filename extension. Both are capable of linking against the C++ standard library, but only g++ does this by default. So if you have a program written in C++ that doesn't happen to need to link against the standard library, gcc will happen to do the right thing; but then, so would g++. So there's really no reason not to use g++ for general C++ development.
我对这个问题产生了兴趣,并执行了一些实验
我发现描述在这里,但是很短。
然后,我尝试在Windows机器上尝试gcc.exe和g ++。exe:
我尝试编译C89,C99和C ++ 1998 Simple Test Files,并且非常适合我的语言匹配的正确扩展名
的正确扩展名,但是当我尝试运行“ GNU编译器集合”时,以这种方式的工具:
,
,但仍然没有错误
,
,这也是
P.S.测试文件
调查结果:
如果查看过程树,则GCC和G ++似乎是后端到其他工具,在我的环境中是: cc1plus.exe,cc1.exe, collect2.exe,as.exe,ld.exe
gcc gcc可以作为metatoot效果,如果您有正确的扩展名或正确设置
-STD -X标志。请参阅 this
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
来自使用GNU Compiler Collection(GCC):
您可以阅读更多在这里。
From Using the GNU Compiler Collection (GCC):
You could read more here.
GCC和G ++都是GNU编译器。它们都编译C和C ++。 *.c文件GCC将其视为AC程序,而G ++将其视为AC ++程序。 *.CPP文件被认为是C ++程序。 C ++是一组C ++,语法更严格,因此请注意后缀。
gcc and g ++ are both GNU compiler. They both compile c and c++. The difference is for *.c files gcc treats it as a c program, and g++ sees it as a c ++ program. *.cpp files are considered to be c ++ programs. c++ is a super set of c and the syntax is more strict, so be careful about the suffix.
我正在Linux系统中测试GCC和G ++。通过使用MakeFile,我可以定义“ GNU Make”使用的纯正者。我用所谓的“动态内存”定位“ C Plus”的功能进行了测试:
只有G ++可以在我的计算机上成功编译,而GCC会报告错误
,因此我自己的结论是GCC不完全支持“ C Plus”。 似乎为C ++源文件选择G ++是一个更好的选择。
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.
G ++和GCC都是GNU编译器Collection(GCC)提供的编译器,主要区别在于它们主要设计用于编译的语言。
GCC:
GCC是C的GNU编译器。它主要用于编译C程序。
当您使用GCC编译源文件时,它假设代码是用C ++编写的
:
G ++是C ++的GNU编译器。它是专门为编译C ++程序而设计的。
当您使用G ++编译源文件时,它将代码视为C ++代码,从而启用C ++功能和标准。
g++ and gcc are both compilers provided by the GNU Compiler Collection (GCC), and the main difference lies in the languages they are primarily designed to compile.
gcc:
gcc is the GNU Compiler for C. It is primarily used for compiling C programs.
When you use gcc to compile a source file, it assumes that the code is written in C.
g++:
g++ is the GNU Compiler for C++. It is specifically designed for compiling C++ programs.
When you use g++ to compile a source file, it treats the code as C++ code, enabling C++ features and standards.