在Code :: Blocks中启用`-std = c ++ 14`标志 [英] Enabling `-std=c++14` flag in Code::Blocks

查看:247
本文介绍了在Code :: Blocks中启用`-std = c ++ 14`标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为Windows安装了Code :: Blocks,并希望编译C ++ 14代码,比如通用lambdas,但是我已经从codeblocks.org 不支持标志
-std = c ++ 14



如何更新编译器并启用Code :: Blocks的 -std = c ++ 14 标志?

解决方案

要在Code :: Blocks中使用C ++ 14编译源代码,首先需要下载并安装一个支持


    li>从此处(特定版本)或下载MinGW从官方网站更改为选择选项
  1. 将其解压缩为例如:C:\(result将为C:\MinGW)

  2. 打开Code :: Blocks

  3. 前往[设定] => [编译器]。

  4. 前往[工具链执行档]。

  5. 将目录更改为解压缩编译器的目录。例如C:\ MinGW。

  6. 更改Program Files下的所有必要文件以匹配C:\MinGW\bin下的文件:

>


  1. 在您点击确定之前,请转到最左侧的选项卡编译器设置。

  2. 选择编译器标志。

  3. 为了简单起见,右键单击列表中的新标志:


b $ b

>


  1. 输入以下内容并点击确定,然后点击您刚刚创建的标记框:

>



< ol start =12>
  • 最后,需要指定调试器路径。转到设置=>调试器,单击左侧的Defualt,然后输入可执行文件的新完整路径:






  • 现在,尝试编译一个有C ++ 14特性的程序:

      #include< iostream> 
    #include< string>
    using namespace std;

    auto main() - > int
    {
    auto add_two([](auto x,auto y){return x + y;});

    cout<< add_two(Is,ts)<< 工作! << endl;
    }


    I have installed Code::Blocks for Windows and want to compile C++14 code like generic lambdas but the binary version of Code::Blocks that I've installed from codeblocks.org doesn't support the flag
    -std=c++14.

    How do I update the compiler and enable -std=c++14 flag for Code::Blocks?

    解决方案

    To compile your source code using C++14 in Code::Blocks, you first of all need to download and install a compiler that supports C++14 features.

    Here’s how you can do it on Windows:

    1. Download MinGW from here (particular build) or from official site to choose options
    2. Extract it to for example: C:\ (result will be C:\MinGW)
    3. Open Code::Blocks
    4. Go to Settings => Compiler.
    5. Go to "Toolchain Executables".
    6. In the top field "Compiler’s installation directory", change the directory to the one where you extracted the compiler. E.g C:\MinGW.
    7. Change all the necessary files under "Program Files" to match the files under C:\MinGW\bin:

    1. Before you hit "OK", go to the leftmost tab "Compiler settings".
    2. Select "Compiler Flags".
    3. For simplicity, right click in the list somewhere and select "New Flag":

    1. Type in the following and click "OK", and tic the box of the flag you just created:

    1. Lastly, you need to specify the debugger path. Go to "Settings" => "Debugger", click "Defualt" on left hand side and enter the new full path of the executable:


    Now, try to compile a program with C++14 features:

    #include <iostream>
    #include <string>
    using namespace std;
    
    auto main() -> int
    {
        auto add_two([](auto x, auto y){ return x + y; });
    
        cout << add_two("I"s, "t"s) << " works!" << endl;
    }
    

    这篇关于在Code :: Blocks中启用`-std = c ++ 14`标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆