gcc和g++的区别
参考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:
- 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.
- Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this).
- gcc compiling C files has less predefined macros.
- 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++的区别的更多相关文章
- Linux - gcc和g++的区别
一般linux系统都自带了gcc编译器的,你可以用你的安装光盘去安装,如果你是觉得自带的gcc版本太低了,可以去gcc的官方网站可以下载到,编译需要很长的时间,如果你只编译C或者C++可以只下载gcc ...
- 【转载】gcc和g++的区别
[说明]本文转载自 静心 的文章 http://blog.163.com/lu_jun520/blog/static/5699613420116205148239/ 一般linux系统都自带了gcc编 ...
- gcc和g++的区别【转自中国源码网】
gcc和g++的区别[转自中国源码网] gcc和g++都是GNU(组织)的一个编译器. 误区一:gcc只能编译c代码,g++只能编译c++代码两者都可以,但是请注意:1.后缀为.c的,gcc把它当作是 ...
- linux中gcc和g++的区别
1.两者都是编译器 2.gcc编译c语言:g++既可以编译c语言,也可以编译c++语言 3.gcc不能自动链接库文件,一般用g++来链接库文件,非要用gcc的话,一般使用gcc -lstdc++命令 ...
- gcc 与 g++的区别
原文: http://www.cnblogs.com/wb118115/p/5969775.html ------------------------------------------------- ...
- 【C/C++】Linux的gcc和g++的区别
Windows中我们常用vs来编译编写好的C和C++代码:vs把编辑器,编译器和调试器等工具都集成在这一款工具中,在Linux下我们能用什么工具来编译所编写好的代码呢,其实Linux下这样的工具有很多 ...
- 结合python版本安装python-devel gcc和g++的区别 安装前做yum搜索
[test@ecs autocloudservices]# yum install python-develLoaded plugins: fastestmirrorLoading mirror sp ...
- gcc 与g++的区别
原文 http://www.cnblogs.com/wb118115/p/5969775.html 什么是gcc / g++ 首先说明:gcc 和 GCC 是两个不同的东西 GCC:GNU Compi ...
- gcc和g++的区别:安装、版本、编译(转)
用以下命令: yum install gcc 安装的只有gcc,而不会安装g++.gcc是编译器合集,而gcc-g++或简称g++则是C++编译器.gcc成为了编译器的选择器.gcc通过识别被编译的源 ...
- gcc与g++的区别
一:gcc与g++比较 编译c/c++代码的时候,有人用gcc,有人用g++,于是各种说法都来了,譬如c代码用gcc,而 c++代码用g++,或者说编译用gcc,链接用g++,一时也不知哪个说法正确, ...
随机推荐
- 微信平台(一)--获取access_token
事前思路准备 说在前面:如果要获取access_token,那么你需要appid,appsecret;另外需要post请求连接https://api.weixin.qq.com/cgi-bin/tok ...
- Swift学习的新工具---REPL
从xcode6.1开始,苹果官方提供了一个新的辅助开发swift的工具,即repl(read eval print loop) OS X Yosemite系统下,打开终端应用程序,输入swift: 如 ...
- 18_高级映射:一对一查询(使用resultMap)
[简述] 数据库模型和数据等信息与上一篇博文相同. 需求也同上一篇博文. [工程截图] [User.java]POJO package cn.higgin.mybatis.po; import jav ...
- 暑假集训(3)第三弹 -----Til the Cows Come Home(Poj2387)
题意梗概:据说母牛在产奶的时候,因为奶量太充足,希望有人帮它挤奶,它回家就很快.我们便能喝到鲜美的 牛奶,不过,贫奶季节却大不相同,它会懒洋洋的在大草原上晃来晃去的晒太阳,而不会想到马上回家,这可不 ...
- 暑假集训(2)第八弹 ----- Hero(hdu4310)
K - Hero Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:65536KB 64bit ...
- 九度OJ 1497 面积最大的全1子矩阵 -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1497 题目描述: 在一个M * N的矩阵中,所有的元素只有0和1,从这个矩阵中找出一个面积最大的全1子矩阵,所谓最 ...
- 九度OJ1198 a+b 【高精度整数】
题目地址:http://ac.jobdu.com/problem.php?pid=1198 题目描述: 实现一个加法器,使其能够输出a+b的值. 输入: 输入包括两个数a和b,其中a和b的位数不超过1 ...
- Apose 套打
给web添加一个dll引用:Apose.Words 下载链接:http://yunpan.cn/cA7v6uceM6KVw 提取码 11df 在Global.asax里面的Application_S ...
- POJ2255二叉树
题目大意就是给出你一个二叉树的前序和中序,要你求后序. 思路:二叉树的排序就是根据根节点的位置来定义的.所以找到二叉树的根节点是最重要的,二叉树的左子树和右子树也可以看成是二叉树,以此递归: #inc ...
- HTTP协议(4)
HTTP 概括总结 方便以后使用.遗忘时有侧重点的去学习,方便查阅: 开始看到webservice 和restful 有些不理解 现在可以简单理解为 : webservice = http协议+XM ...