AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1064113
Accepted
Soo
Soo
Asked: 2018-08-11 02:26:35 +0800 CST2018-08-11 02:26:35 +0800 CST 2018-08-11 02:26:35 +0800 CST

在 GCC 7.3 中禁用 C++11

  • 772

似乎在 Ubuntu 18.04 中,默认提供的 g++(版本 7.3.0)默认以 C++11 兼容模式运行。我的旧代码中出现了一些与 C++11 不兼容的错误。我安装了 g++-6(版本 6.4.0)并且程序编译正常。是否可以在 g++-7 中禁用 C++11 模式?

gcc c++ g++
  • 2 2 个回答
  • 7428 Views

2 个回答

  • Voted
  1. Best Answer
    pim
    2018-08-11T02:48:14+08:002018-08-11T02:48:14+08:00

    尝试添加-std=gnu++98,这可能是 gcc 6.4.0 的默认设置。

    例子:

    g++ -std=gnu++98 hello.cpp -o hello
    
    • 21
  2. abu_bua
    2018-08-31T07:14:19+08:002018-08-31T07:14:19+08:00

    您可以从中man g++选择不同的方言:

    Options Controlling C Dialect
       The following options control the dialect of C (or languages derived
       from C, such as C++, Objective-C and Objective-C++) that the compiler
       accepts:
    
      -ansi
           In C mode, this is equivalent to -std=c90. In C++ mode, it is
           equivalent to -std=c++98.
    
           This turns off certain features of GCC that are incompatible with
           ISO C90 (when compiling C code), or of standard C++ (when compiling
           C++ code), such as the "asm" and "typeof" keywords, and predefined
           macros such as "unix" and "vax" that identify the type of system
           you are using.  It also enables the undesirable and rarely used ISO
           trigraph feature.  For the C compiler, it disables recognition of
           C++ style // comments as well as the "inline" keyword.
    
      -std=
           Determine the language standard.   This option is currently only
           supported when compiling C or C++.
    
           The compiler can accept several base standards, such as c90 or
           c++98, and GNU dialects of those standards, such as gnu90 or
           gnu++98.  When a base standard is specified, the compiler accepts
           all programs following that standard plus those using GNU
           extensions that do not contradict it.  For example, -std=c90 turns
           off certain features of GCC that are incompatible with ISO C90,
           such as the "asm" and "typeof" keywords, but not other GNU
           extensions that do not have a meaning in ISO C90, such as omitting
           the middle term of a "?:" expression. On the other hand, when a GNU
           dialect of a standard is specified, all features supported by the
           compiler are enabled, even when those features change the meaning
           of the base standard.  As a result, some strict-conforming programs
           may be rejected.  The particular standard is used by -Wpedantic to
           identify which features are GNU extensions given that version of
           the standard. For example -std=gnu90 -Wpedantic warns about C++
           style // comments, while -std=gnu99 -Wpedantic does not.
    
           A value for this option must be provided; possible values are
    
           c90
           c89
           iso9899:1990
               Support all ISO C90 programs (certain GNU extensions that
               conflict with ISO C90 are disabled). Same as -ansi for C code.
    
           iso9899:199409
               ISO C90 as modified in amendment 1.
    
           c99
           c9x
           iso9899:1999
           iso9899:199x
               ISO C99.  This standard is substantially completely supported,
               modulo bugs and floating-point issues (mainly but not entirely
               relating to optional C99 features from Annexes F and G).  See
               <http://gcc.gnu.org/c99status.html> for more information.  The
               names c9x and iso9899:199x are deprecated.
    
           c11
           c1x
           iso9899:2011
               ISO C11, the 2011 revision of the ISO C standard.  This
               standard is substantially completely supported, modulo bugs,
               floating-point issues (mainly but not entirely relating to
               optional C11 features from Annexes F and G) and the optional
               Annexes K (Bounds-checking interfaces) and L (Analyzability).
               The name c1x is deprecated.
    
           gnu90
           gnu89
               GNU dialect of ISO C90 (including some C99 features).
    
           gnu99
           gnu9x
               GNU dialect of ISO C99.  The name gnu9x is deprecated.
    
           gnu11
           gnu1x
               GNU dialect of ISO C11.  This is the default for C code.  The
               name gnu1x is deprecated.
    
           c++98
           c++03
               The 1998 ISO C++ standard plus the 2003 technical corrigendum
               and some additional defect reports. Same as -ansi for C++ code.
           gnu++98
           gnu++03
               GNU dialect of -std=c++98.
    
           c++11
           c++0x
               The 2011 ISO C++ standard plus amendments.  The name c++0x is
               deprecated.
    
           gnu++11
           gnu++0x
               GNU dialect of -std=c++11.  The name gnu++0x is deprecated.
    
           c++14
           c++1y
               The 2014 ISO C++ standard plus amendments.  The name c++1y is
               deprecated.
    
           gnu++14
           gnu++1y
               GNU dialect of -std=c++14.  This is the default for C++ code.
               The name gnu++1y is deprecated.
    
           c++1z
               The next revision of the ISO C++ standard, tentatively planned
               for 2017.  Support is highly experimental, and will almost
               certainly change in incompatible ways in future releases.
    
           gnu++1z
               GNU dialect of -std=c++1z.  Support is highly experimental, and
               will almost certainly change in incompatible ways in future
               releases.
    
    • 1

相关问题

  • 如何选择默认的 gcc 和 g++ 版本?

  • itoa() 在 Gcc >=4.1 的 stdlib.h 中是否可用?

  • 代码块中的错误编译器错误

  • 如何安装 gcc-4.1?

  • 在哪里可以找到预编译的 gcc 3.4.6 或 2.95 ARM 交叉编译器?[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve