参考What is the difference between g++ and gcc?

1.The actual compiler is "cc1" for C and "cc1plus" for C++; both gcc and g++ are drivers (which call the preprocessor/compiler/assembler/linker as needed).

2.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).

3.You can link the std C++ library in gcc by passing -lstdc++ parameter.

4.GCC: GNU Compiler Collection

  • Referrers to all the different languages that are supported by the GNU compiler.

gcc: GNU C      Compiler

g++: GNU C++ Compiler

The main differences:

  1. gcc will compile: *.c/*.cpp files as C and C++ respectively.
  2. g++ will compile: *.c/*.cpp files but they will all be treated as C++ files.
  3. Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
  4. gcc compiling C files has less predefined macros.
  5. gcc compiling *.cpp and g++ compiling *.c/*.cpp files has a few extra macros.

Extra Macros when compiling *.cpp files:

#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern

综上所述:

1.gcc和g++只是一个前端,真正执行编译的是c语言对应的"cc1"和c++对应的"cc1plus"。

2.gcc可以编译、链接c和c++,通过后缀名.c和.cpp来区分。但链接时必须添加-lstdc++参数才能保证c++的正确链接,c语言不用。

3.g++用来编译、链接c++,无论后缀是.c或.cpp,都会当做c++来处理。因为是专为c++做的编译工具,所以编译c++一般用g++。

4.gcc和g++在编译c++时会额外添加几个宏,如上第四点提到的。

gcc和g++的区别的更多相关文章

  1. Linux - gcc和g++的区别

    一般linux系统都自带了gcc编译器的,你可以用你的安装光盘去安装,如果你是觉得自带的gcc版本太低了,可以去gcc的官方网站可以下载到,编译需要很长的时间,如果你只编译C或者C++可以只下载gcc ...

  2. 【转载】gcc和g++的区别

    [说明]本文转载自 静心 的文章 http://blog.163.com/lu_jun520/blog/static/5699613420116205148239/ 一般linux系统都自带了gcc编 ...

  3. gcc和g++的区别【转自中国源码网】

    gcc和g++的区别[转自中国源码网] gcc和g++都是GNU(组织)的一个编译器. 误区一:gcc只能编译c代码,g++只能编译c++代码两者都可以,但是请注意:1.后缀为.c的,gcc把它当作是 ...

  4. linux中gcc和g++的区别

    1.两者都是编译器 2.gcc编译c语言:g++既可以编译c语言,也可以编译c++语言 3.gcc不能自动链接库文件,一般用g++来链接库文件,非要用gcc的话,一般使用gcc -lstdc++命令 ...

  5. gcc 与 g++的区别

    原文: http://www.cnblogs.com/wb118115/p/5969775.html ------------------------------------------------- ...

  6. 【C/C++】Linux的gcc和g++的区别

    Windows中我们常用vs来编译编写好的C和C++代码:vs把编辑器,编译器和调试器等工具都集成在这一款工具中,在Linux下我们能用什么工具来编译所编写好的代码呢,其实Linux下这样的工具有很多 ...

  7. 结合python版本安装python-devel gcc和g++的区别 安装前做yum搜索

    [test@ecs autocloudservices]# yum install python-develLoaded plugins: fastestmirrorLoading mirror sp ...

  8. gcc 与g++的区别

    原文 http://www.cnblogs.com/wb118115/p/5969775.html 什么是gcc / g++ 首先说明:gcc 和 GCC 是两个不同的东西 GCC:GNU Compi ...

  9. gcc和g++的区别:安装、版本、编译(转)

    用以下命令: yum install gcc 安装的只有gcc,而不会安装g++.gcc是编译器合集,而gcc-g++或简称g++则是C++编译器.gcc成为了编译器的选择器.gcc通过识别被编译的源 ...

  10. gcc与g++的区别

    一:gcc与g++比较 编译c/c++代码的时候,有人用gcc,有人用g++,于是各种说法都来了,譬如c代码用gcc,而 c++代码用g++,或者说编译用gcc,链接用g++,一时也不知哪个说法正确, ...

随机推荐

  1. Thinkphp 使用gmail发送邮件

    1.Thinkphp 发送邮件内容来自:http://www.thinkphp.cn/code/32.html /** * 系统邮件发送函数 * @param string $to 接收邮件者邮箱 * ...

  2. js如何实现一定时间后去执行一个函数

    js如何实现一定时间后去执行一个函数:在实际需要中可能需要规定在指定的时间之后再去执行一个函数以达成期望的目的,这也就是一个定时器效果,恰好在js中就已经给定了这样的一个函数setTimeout(), ...

  3. Apache Mesos总体架构

    http://developer.51cto.com/art/201401/426507.htm 1. 前言 同其他大部分分布式系统一样,Apache Mesos为了简化设计,也是采用了master/ ...

  4. SQL server 数据库日志文件过大清空日志文件

    SQL2008:'在SQL2008中清除日志就必须在简单模式下进行,等清除动作完毕再调回到完全模式. USE [master] GO ALTER DATABASE DBName SET RECOVER ...

  5. HW--自守数

    package testcase; import huawei.Demo; import junit.framework.TestCase;//加入测试框架,不需要写Main函数 public cla ...

  6. 新安装Eclipse后的一些配置

    配置护眼的背景色 Window-> Preferences-> General-> Editors-> Text Editors: Appearance color optio ...

  7. sql的集合操作

    原文转自:http://blog.csdn.net/qsyzb/article/details/12560917 SELECT语句的查询结果是元组的集合,所以多个SELECT语句的结果可进行集合操作. ...

  8. Linux启动提示“unexpected inconsistency;RUN fsck MANUALLY”

    问题:在开机启动时,提示“unexpected inconsistency;RUN fsck MANUALLY”进不了系统 解决方法: fsck不仅可以对文件系统进行扫描,还能修正文件系统的一些问题, ...

  9. mysql常见的hint(转载的)

    mysql常用的hint对于经常使用oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在mysql里,也有类似的hint功能.下面介绍一些常用的. ...

  10. 由Double类型数据到数据的格式化包java.text

    需求:Double类型数据截取操作保留两位小数 解决方案: java.text.DecimalFormat df =new java.text.DecimalFormat("#.00&quo ...