link options and how g++ is invoked gcc g++
yum install gcc
yum install gcc-c++
yum reinstall gcc gcc-c++
Downloading packages:
(1/2): gcc-c++-4.8.5-28.el7_5.1.x86_64.rpm | 7.2 MB 00:00:00
(2/2): gcc-4.8.5-28.el7_5.1.x86_64.rpm | 16 MB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total 47 MB/s | 23 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gcc-4.8.5-28.el7_5.1.x86_64 1/2
Installing : gcc-c++-4.8.5-28.el7_5.1.x86_64 2/2
Verifying : gcc-4.8.5-28.el7_5.1.x86_64 1/2
Verifying : gcc-c++-4.8.5-28.el7_5.1.x86_64 2/2
Installed:
gcc.x86_64 0:4.8.5-28.el7_5.1 gcc-c++.x86_64 0:4.8.5-28.el7_5.1
Complete!
[root@txy ~]# which gcc
/usr/bin/gcc
[root@txy ~]# which g++
/usr/bin/g++
https://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html
Next: C Dialect Options, Previous: Overall Options, Up: Invoking GCC [Contents][Index]
3.3 Compiling C++ Programs
C++ source files conventionally use one of the suffixes ‘.C’, ‘.cc’, ‘.cpp’, ‘.CPP’, ‘.c++’, ‘.cp’, or ‘.cxx’; C++ header files often use ‘.hh’, ‘.hpp’, ‘.H’, or (for shared template code) ‘.tcc’; and preprocessed C++ files use the suffix ‘.ii’. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc
).
However, the use of gcc
does not add the C++ library. g++
is a program that calls GCC and automatically specifies linking against the C++ library. It treats ‘.c’, ‘.h’ and ‘.i’ files as C++ source files instead of C source files unless -x is used. This program is also useful when precompiling a C header file with a ‘.h’ extension for use in C++ compilations. On many systems, g++
is also installed with the name c++
.
When you compile C++ programs, you may specify many of the same command-line options that you use for compiling programs in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for C++ programs. See Options Controlling C Dialect, for explanations of options for languages related to
Using the GNU Compiler Collection (GCC): Link Options https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
c++ - What is the difference between g++ and gcc? - Stack Overflow https://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc/172592#172592
gcc
and g++
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 to gcc -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).
gcc和g++的区别 - 苦涩的茶 - 博客园 https://www.cnblogs.com/liushui-sky/p/7729838.html
两者都可以,但是请注意:
if(argv == 0) return;
}
int printString(char* string)
sprintf(string, "This is a test.\n");
}
实际上,这个宏只是标志着编译器将会把代码按C还是C++语法来解释,如上所述,如果后缀为.c,并且采用gcc编译器,则该宏就是未定义的,否则,就是已定义。
严格来说,这句话不算错误,但是它混淆了概念,应该这样说:编译可以用gcc/g++,而链接可以用g++或者gcc -lstdc++。因为gcc命令不能自动和C++程序使用的库联接,所以通常使用g++来完成联接。但在编译阶段,g++会自动调用gcc,二者等价。
实际上并无关系,无论是gcc还是g++,用extern "c"时,都是以C的命名方式来为symbol命名,否则,都以c++方式命名。试验如下:
me.h:
extern "C" void CppPrintf(void);
#include <iostream>
#include "me.h"
using namespace std;
void CppPrintf(void)
{
cout << "Hello\n";
}
#include <stdlib.h>
#include <stdio.h>
#include "me.h"
int main(void)
{
CppPrintf();
return 0;
}
[root@root G++]# g++ -S me.cpp //g++的参数-S: 是指把文件编译成为汇编代码
[root@root G++]# less me.s
.globl _Z9CppPrintfv //注意此函数的命名
.type CppPrintf, @function
[root@root GCC]# less me.s
.globl _Z9CppPrintfv //注意此函数的命名
.type CppPrintf, @function
完全相同!
2. 去掉me.h中extern "C",看用gcc和g++命名有什么不同
[root@root GCC]# gcc -S me.cpp
[root@root GCC]# less me.s
.globl _Z9CppPrintfv //注意此函数的命名
.type _Z9CppPrintfv, @function
[root@root G++]# less me.s
.globl _Z9CppPrintfv //注意此函数的命名
.type _Z9CppPrintfv, @function
完全相同!
link options and how g++ is invoked gcc g++的更多相关文章
- CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)
---恢复内容开始--- CentOS 6.6 升级GCC G++ (当前最新GCC/G++版本为v6.1.0) 没有便捷方式, yum update.... yum install 或者 添加y ...
- 【转】CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)
原文地址:https://www.cnblogs.com/lzpong/p/5755678.html 我这里是centos7 升级到gcc8.1,过程差不多,参考这篇文章,记录一下. ---原文--- ...
- Linux 编译工具 gcc/g++、Make/Makefile、CMake/CMakeLists.txt、qmake
前言 编译器的主要工作流程: 源码(Source Code)>> 预处理器(Preprocessor)>> 编译器(Compiler)>> 汇编程序(Assembl ...
- Linux-编译器gcc/g++编译步骤
gcc和g++现在是gnu中最主要和最流行的c&c++编译器.g++是c++的命令,以.cpp为主:对于c语言后缀名一般为.c,这时候命令换做gcc即可.编译器是根据gcc还是g++来确定是按 ...
- gcc/g++ 静态动态库 混链接.
我的环境: centos6 x64. gcc4.4.7 在使用gcc/g++ 编译程序时我们希望指向一些库是使用静态的链接方式. 另外的一些是动态的方式. 我以boost 为例. 如果我们要使用静态库 ...
- gcc g++ 参数介绍
C和C++ 编译器是集成的.他们都要用四个步骤中的一个或多个处理输入文件: 预处理 (preprocessing),编译(compilation),汇编(assembly)和连接(linking).源 ...
- Options for Debugging Your Program or GCC
[Options for Debugging Your Program or GCC] -g Produce debugging information in the operating system ...
- Linux gcc/g++链接编译顺序详解
gcc/g++链接时对库的顺序要求 -Ldir Add directory dir to the list of directories to be searched for -l. -llibrar ...
- 修改gcc/g++默认include路径
修改gcc/g++默认include路径 转自:http://www.network-theory.co.uk/docs/gccintro/gccintro_23.htmlhttp://ilewen. ...
随机推荐
- SSH整合简单例子
说明:简单SSH整合,struts版本2.3.32,spring版本3.2.9,hibernate版本3.6.10 一.开发步骤 1 引jar包,创建用户library.使用的包和之前博文相同,可以参 ...
- 基于Verilog语言的FIR滤波【程序和理解】
一直想找一个简单.清晰.明了的fir滤波器的设计,终于找到了一个可以应用的,和大家分享一下,有助于FPGA新手入门. 1.说道fir滤波器,滤波系数肯定是最重要的,因为后面程序中涉及到滤波系数问题,所 ...
- Windows调试神器:WinDBG
Q:WinDBG的Watch窗口中我想要查看长字符串,但是后面的内容都被省略为...了怎么办? A:如图,双击你要查看的内容,出现光标后,移动光标即可查看后面被省略的内容 Q:WinDBG如何给程序设 ...
- Vue 混合
混合(mixins)是一种分发vue组件中可复用功能的非常灵活的方式.混合对象可以可以包含任意组件选项.以组件使用混合对象时,所有混合对象的选项将被混合到该组件本身的选项. //定义一个混合对象 va ...
- FileMonitorKit 文件操作监控工具
本人业余时间写的一款文件操作监控工具,功能稳定.效果非常好,有兴趣的网友能够下载玩玩. 下载地址: 32位:http://pan.baidu.com/s/1o64ZFIi FileM ...
- 机器学习算法( 五、Logistic回归算法)
一.概述 这会是激动人心的一章,因为我们将首次接触到最优化算法.仔细想想就会发现,其实我们日常生活中遇到过很多最优化问题,比如如何在最短时间内从A点到达B点?如何投入最少工作量却获得最大的效益?如何设 ...
- php服务器端与android客户端通信问题
http://www.oschina.net/question/616446_90760
- [转]JS脚本抢腾讯云学生1元代金券
转自:http://blog.csdn.net/lkxlaz/article/details/54909397 今天抢代金券,在网上看到的,虽然脚本很easy,但也mark一下吧. //make th ...
- angular 输入属性@Input , 输出属性@Output , 中间人模式
1 输入属性 通常用于父组件向子组件传递信息 举个栗子:我们在父组件向子组件传递股票代码,这里的子组件我们叫它app-order 首先在app.order.component.ts中声明需要由父组件传 ...
- 【Mac + Python3.6 + ATX基于facebook-wda】之IOS自动化(三):facebook-wda库--API学习以及附录:Github上对WDA的问题解答
下面简单介绍facebook-wda库--API的学习 import wda # debug模式,会在run运行时控制台生成消息 wda.DEBUG = False # False 关闭,True开启 ...