How to Enable C++11 in Clion

How to enable C++11 in CLion?

I tried to set CMAKE_C_FLAGS

According to the documentation the CMAKE_C_FLAGS set C language flags for all build types. For C++ you need use CMAKE_CXX_FLAGS instead:

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

Set C11 as default Language in Clion

Depending on the version of Clion you will either see the CMakeLists.txt contain something like

set(CMAKE_CXX_FLAGS "-std=c++11")

or for recent EAP builds

set(CMAKE_CXX_STANDARD 11)

Simply change the variables and flags to the correct ones for C.

There's currently no way (that I know of) to make it use C language as default for new projects. You must manually edit the project CMakeLists.txt file.


With recent versions of CLion you can now create C projects as well, making this answer somewhat obsolete.

Enable C++14 support in CLion?

Now clion supports c++14. set(CMAKE_CXX_STANDARD 14) in CMakeLists.txt

CLion disable C++98 mode in favour of C++11

This has been resolved by adding add_definitions(-std=c++11) to the end of CMakeLists.txt instead of in ALT+SHIFT+F10's command line arguments.

How to enable all compiler warnings in CLion?

Try to set compiler flag in CMakeLists.txt:

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")

Related question: How to enable C++11 in CLion?

How do I set up CLion to compile and run?

I ran into the same issue with CLion 1.2.1 (at the time of writing this answer) after updating Windows 10. It was working fine before I had updated my OS. My OS is installed in C:\ drive and CLion 1.2.1 and Cygwin (64-bit) are installed in D:\ drive.

The issue seems to be with CMake. I am using Cygwin. Below is the short answer with steps I used to fix the issue.

SHORT ANSWER (should be similar for MinGW too but I haven't tried it):

  1. Install Cygwin with GCC, G++, GDB and CMake (the required versions)
  2. Add full path to Cygwin 'bin' directory to Windows Environment variables
  3. Restart CLion and check 'Settings' -> 'Build, Execution, Deployment' to make sure CLion has picked up the right versions of Cygwin, make and gdb
  4. Check the project configuration ('Run' -> 'Edit configuration') to make sure your project name appears there and you can select options in 'Target', 'Configuration' and 'Executable' fields.
  5. Build and then Run
  6. Enjoy

LONG ANSWER:

Below are the detailed steps that solved this issue for me:

  1. Uninstall/delete the previous version of Cygwin (MinGW in your case)

  2. Make sure that CLion is up-to-date

  3. Run Cygwin setup (x64 for my 64-bit OS)

  4. Install at least the following packages for Cygwin:

    gcc
    g++
    make
    Cmake
    gdb

    Make sure you are installing the correct versions of the above packages that CLion requires. You can find the required version numbers at CLion's Quick Start section (I cannot post more than 2 links until I have more reputation points).

  5. Next, you need to add Cygwin (or MinGW) to your Windows Environment Variable called 'Path'. You can Google how to find environment variables for your version of Windows

[On Win 10, right-click on 'This PC' and select Properties -> Advanced system settings -> Environment variables... -> under 'System Variables' -> find 'Path' -> click 'Edit']


  1. Add the 'bin' folder to the Path variable. For Cygwin, I added:
    D:\cygwin64\bin

  2. Start CLion and go to 'Settings' either from the 'Welcome Screen' or from File -> Settings

  3. Select 'Build, Execution, Deployment' and then click on 'Toolchains'

  4. Your 'Environment' should show the correct path to your Cygwin installation directory (or MinGW)

  5. For 'CMake executable', select 'Use bundled CMake x.x.x' (3.3.2 in my case at the time of writing this answer)

  6. 'Debugger' shown to me says 'Cygwin GDB GNU gdb (GDB) 7.8' [too many gdb's in that line ;-)]

  7. Below that it should show a checkmark for all the categories and should also show the correct path to 'make', 'C compiler' and 'C++ compiler'

See screenshot:
Check all paths to the compiler, make and gdb


  1. Now go to 'Run' -> 'Edit configuration'. You should see your project name in the left-side panel and the configurations on the right side

See screenshot:
Check the configuration to run the project


  1. There should be no errors in the console window. You will see that the 'Run' -> 'Build' option is now active

  2. Build your project and then run the project. You should see the output in the terminal window

Hope this helps! Good luck and enjoy CLion.

Compiling C++17 using CLion, CMake and the VS2017 compiler

The CMAKE_CXX_STANDARD variable is used to initialize the CXX_STANDARD property.

From the property documentation:

For compilers that have no notion of a standard level, such as MSVC,
this has no effect.

For Visual Studio 2017 with plain CMake, the canonical way for C++17 (the default is C++14) is:

target_compile_options(optional2 PRIVATE /std:c++latest)


Related Topics



Leave a reply



Submit