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 invokedg++ 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

gcc和g++的区别
 
  我们在编译c/c++代码的时候,有人用gcc,有人用g++,于是各种说法都来了,譬如c代码用gcc,而c++代码用g++,或者说编译用gcc,链接用g++,一时也不知哪个说法正确,如果再遇上个extern "C",分歧就更多了,这里我想作个了结,毕竟知识的目的是令人更清醒,而不是更糊涂。
 
误区一:gcc只能编译c代码,g++只能编译c++代码
两者都可以,但是请注意:
1.后缀为.c的,gcc把它当作是C程序,而g++当作是c++程序;后缀为.cpp的,两者都会认为是c++程序,注意,虽然c++是c的超集,但是两者对语法的要求是有区别的,例如:
#include <stdio.h>
int main(int argc, char* argv[])
{
   if(argv == 0) return;
   printString(argv);
   return;
}
int printString(char* string)
{
  sprintf(string, "This is a test.\n");
}
如果按照C的语法规则,OK,没问题,但是,一旦把后缀改为cpp,立刻报三个错:
“printString未定义”;
“cannot convert `char**' to `char*”;
”return-statement with no value“;
    这3个错分别对应前面红色标注的部分。可见C++的语法规则更加严谨一些。
 
2.编译阶段,g++会调用gcc,对于c++代码,两者是等价的,但是因为gcc命令不能自动和C++程序使用的库联接,所以通常用g++来完成链接,为了统一起见,干脆编译/链接统统用g++了,这就给人一种错觉,好像cpp程序只能用g++似的。
 
误区二:gcc不会定义__cplusplus宏,而g++会
实际上,这个宏只是标志着编译器将会把代码按C还是C++语法来解释,如上所述,如果后缀为.c,并且采用gcc编译器,则该宏就是未定义的,否则,就是已定义。
 
误区三:编译只能用gcc,链接只能用g++
严格来说,这句话不算错误,但是它混淆了概念,应该这样说:编译可以用gcc/g++,而链接可以用g++或者gcc -lstdc++。因为gcc命令不能自动和C++程序使用的库联接,所以通常使用g++来完成联接。但在编译阶段,g++会自动调用gcc,二者等价。
 
误区四:extern "C"与gcc/g++有关系
实际上并无关系,无论是gcc还是g++,用extern "c"时,都是以C的命名方式来为symbol命名,否则,都以c++方式命名。试验如下:
me.h
extern "C" void CppPrintf(void);
 
me.cpp:
#include <iostream>
#include "me.h"
using namespace std;
void CppPrintf(void)
{
     cout << "Hello\n";
}
 
test.cpp:
#include <stdlib.h>
#include <stdio.h>
#include "me.h"        
int main(void)
{
    CppPrintf();
    return 0;
}
 
1. 先给me.h加上extern "C",看用gcc和g++命名有什么不同
[root@root G++]# g++ -S me.cpp     //g++的参数-S: 是指把文件编译成为汇编代码
[root@root G++]# less me.s
.globl _Z9CppPrintfv        //注意此函数的命名
        .type   CppPrintf, @function
[root@root GCC]# gcc -S me.cpp
[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++]# g++ -S me.cpp
[root@root G++]# less me.s
.globl _Z9CppPrintfv        //注意此函数的命名
        .type   _Z9CppPrintfv, @function
完全相同!
【结论】完全相同,可见extern "C"与采用gcc/g++并无关系,以上的试验还间接的印证了前面的说法:在编译阶段,g++是调用gcc的。
转自:http://lpy999.blog.163.com/blog/static/117372061201182042232511/
 
 

link options and how g++ is invoked gcc g++的更多相关文章

  1. CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)

    ---恢复内容开始--- CentOS 6.6 升级GCC G++ (当前最新GCC/G++版本为v6.1.0) 没有便捷方式, yum update....   yum install 或者 添加y ...

  2. 【转】CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)

    原文地址:https://www.cnblogs.com/lzpong/p/5755678.html 我这里是centos7 升级到gcc8.1,过程差不多,参考这篇文章,记录一下. ---原文--- ...

  3. Linux 编译工具 gcc/g++、Make/Makefile、CMake/CMakeLists.txt、qmake

    前言 编译器的主要工作流程: 源码(Source Code)>> 预处理器(Preprocessor)>> 编译器(Compiler)>> 汇编程序(Assembl ...

  4. Linux-编译器gcc/g++编译步骤

    gcc和g++现在是gnu中最主要和最流行的c&c++编译器.g++是c++的命令,以.cpp为主:对于c语言后缀名一般为.c,这时候命令换做gcc即可.编译器是根据gcc还是g++来确定是按 ...

  5. gcc/g++ 静态动态库 混链接.

    我的环境: centos6 x64. gcc4.4.7 在使用gcc/g++ 编译程序时我们希望指向一些库是使用静态的链接方式. 另外的一些是动态的方式. 我以boost 为例. 如果我们要使用静态库 ...

  6. gcc g++ 参数介绍

    C和C++ 编译器是集成的.他们都要用四个步骤中的一个或多个处理输入文件: 预处理 (preprocessing),编译(compilation),汇编(assembly)和连接(linking).源 ...

  7. Options for Debugging Your Program or GCC

    [Options for Debugging Your Program or GCC] -g Produce debugging information in the operating system ...

  8. Linux gcc/g++链接编译顺序详解

    gcc/g++链接时对库的顺序要求 -Ldir Add directory dir to the list of directories to be searched for -l. -llibrar ...

  9. 修改gcc/g++默认include路径

    修改gcc/g++默认include路径 转自:http://www.network-theory.co.uk/docs/gccintro/gccintro_23.htmlhttp://ilewen. ...

随机推荐

  1. SSH整合简单例子

    说明:简单SSH整合,struts版本2.3.32,spring版本3.2.9,hibernate版本3.6.10 一.开发步骤 1 引jar包,创建用户library.使用的包和之前博文相同,可以参 ...

  2. 基于Verilog语言的FIR滤波【程序和理解】

    一直想找一个简单.清晰.明了的fir滤波器的设计,终于找到了一个可以应用的,和大家分享一下,有助于FPGA新手入门. 1.说道fir滤波器,滤波系数肯定是最重要的,因为后面程序中涉及到滤波系数问题,所 ...

  3. Windows调试神器:WinDBG

    Q:WinDBG的Watch窗口中我想要查看长字符串,但是后面的内容都被省略为...了怎么办? A:如图,双击你要查看的内容,出现光标后,移动光标即可查看后面被省略的内容 Q:WinDBG如何给程序设 ...

  4. Vue 混合

    混合(mixins)是一种分发vue组件中可复用功能的非常灵活的方式.混合对象可以可以包含任意组件选项.以组件使用混合对象时,所有混合对象的选项将被混合到该组件本身的选项. //定义一个混合对象 va ...

  5. FileMonitorKit 文件操作监控工具

    本人业余时间写的一款文件操作监控工具,功能稳定.效果非常好,有兴趣的网友能够下载玩玩. 下载地址: 32位:http://pan.baidu.com/s/1o64ZFIi          FileM ...

  6. 机器学习算法( 五、Logistic回归算法)

    一.概述 这会是激动人心的一章,因为我们将首次接触到最优化算法.仔细想想就会发现,其实我们日常生活中遇到过很多最优化问题,比如如何在最短时间内从A点到达B点?如何投入最少工作量却获得最大的效益?如何设 ...

  7. php服务器端与android客户端通信问题

    http://www.oschina.net/question/616446_90760

  8. [转]JS脚本抢腾讯云学生1元代金券

    转自:http://blog.csdn.net/lkxlaz/article/details/54909397 今天抢代金券,在网上看到的,虽然脚本很easy,但也mark一下吧. //make th ...

  9. angular 输入属性@Input , 输出属性@Output , 中间人模式

    1 输入属性 通常用于父组件向子组件传递信息 举个栗子:我们在父组件向子组件传递股票代码,这里的子组件我们叫它app-order 首先在app.order.component.ts中声明需要由父组件传 ...

  10. 【Mac + Python3.6 + ATX基于facebook-wda】之IOS自动化(三):facebook-wda库--API学习以及附录:Github上对WDA的问题解答

    下面简单介绍facebook-wda库--API的学习 import wda # debug模式,会在run运行时控制台生成消息 wda.DEBUG = False # False 关闭,True开启 ...