参考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. 以 280W 数据为依据。对比SQL2008 表分区前和分区后的 T_SQL 效率

    一: 数据库的优化一直项目后期的重中之重,特别是当单表数据庞大到1000W时候.各种SQL语句执行效率都会慢很多.SQL 效率 与索引,行数据,列数据,以及Where 刷选字段类型 (效率 整数型大于 ...

  2. procedure的over(partition by ) function

    转载自:http://www.2cto.com/database/201310/249722.html oracle的分析函数over(Partition by...)   Sql代码       o ...

  3. SharePoint 学习记事(二)

    买了一本<sharepoint2010开发高级编程> 据说评价也不高. 搜到如下文章,留着看看:http://book.douban.com/review/5673741/ http:// ...

  4. 解决 Zabbix agent on [HOSTNAME] is unreachable for 5 minutes

    今天中午发现zabbix陆续出现Zabbix agent on [HOSTNAME] is unreachable for 5 minutes问题,开始是只是寥寥几台,没太在意,吃了顿饭回来发现一大堆 ...

  5. SQL语句与正则表达式

    今儿个才知道SQL语句还可以搭配正则表达式作为查询条件,很是有用. REGEXP_LIKE(匹配)REGEXP_INSTR (包含)REGEXP_REPLACE(替换)REGEXP_SUBSTR(提取 ...

  6. Shell/Bash 变量/variable 循环/loop

    如何在bash脚本里面进行循环 #!/bin/bash n=9999 for(( i =1; i<=100;i++)) do /root/testProgram $n sleep 5 n=$(( ...

  7. makefile--#的不正确使用

    /usr/vacpp/bin/makeC++SharedLib -o /cicm/src/dao/testcase/rel/FUNCTEST.ibmcpp -brtl -bnortllib -p100 ...

  8. OpenJudge 2811 熄灯问题 / Poj 1222 EXTENDED LIGHTS OUT

    1.链接地址: http://bailian.openjudge.cn/practice/2811 http://poj.org/problem?id=1222 2.题目: 总时间限制: 1000ms ...

  9. Linux – RedHat7 / CentOS 7 忘记root密码修改

    1.(a) 开机出现grub boot loader 开机选项菜单时,立即点击键盘任意鍵,boot loader 会暂停. (b) 按下’e’,编辑选项菜单(c) 移动上下鍵至linux16 核心命令 ...

  10. 解决fontawesome-webfont 被拦截的问题

    我们最近的项目是java web项目,前端采用了fontawesome-webfont,项目部署之后,图标都显示不出来,在网上学习了一大圈,找到了一个解决方案可行: web.xml中配置       ...