Section 2 'Bull Cows' example on Linux

Just a quick note on Section 2 with Linux and the use of constexpr - this is something that was introduced with C++11. Unlike in Visual Studio, you’re pretty much left to fend for yourself in Linux in regards to compiler options. If you’re familiar with compiling from the terminal or writing your own make files, you’ll know that to successfully compile the example code that uses constexpr you could use:

g++ -std=c++11 main.cpp -o test

Having said that, you’re probably better off just compiling with the latest version of C++ available on your machine. In my case, this is C++14:

g++ -std=c++14 main.cpp -o test

If you are using CodeLite instead (and I would strongly recommend CodeLite if you’re new to C++ on Linux), then:

  1. Right-click on your project.
  2. Click on the Compiler option.
  3. Click on the ellipses next to C++ Compiler Options.
  4. Select Enable C++14 features [-std=c++14].

You will then be able to build the example without any errors.

  • While I recommend using an IDE like CodeLite, I’d also recommend learning how to compile simple programs/projects directly from the terminal. By doing so, when you use an IDE you’ll understand the compiler and linker options required for various projects.

Privacy & Terms