Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

c++ - Enabling `-std=c++14` flag in Code::Blocks

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:MinGWin:

enter image description here

  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”:

enter image description here

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

enter image description here

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

enter image description here


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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...