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):
- Install Cygwin with GCC, G++, GDB and CMake (the required versions)
- Add full path to Cygwin 'bin' directory to Windows Environment variables
- Restart CLion and check 'Settings' -> 'Build, Execution, Deployment' to make sure CLion has picked up the right versions of Cygwin, make and gdb
- 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.
- Build and then Run
- Enjoy
LONG ANSWER:
Below are the detailed steps that solved this issue for me:
Uninstall/delete the previous version of Cygwin (MinGW in your case)
Make sure that CLion is up-to-date
Run Cygwin setup (x64 for my 64-bit OS)
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).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']
Add the 'bin' folder to the Path variable. For Cygwin, I added:
D:\cygwin64\bin
Start CLion and go to 'Settings' either from the 'Welcome Screen' or from File -> Settings
Select 'Build, Execution, Deployment' and then click on 'Toolchains'
Your 'Environment' should show the correct path to your Cygwin installation directory (or MinGW)
For 'CMake executable', select 'Use bundled CMake x.x.x' (3.3.2 in my case at the time of writing this answer)
'Debugger' shown to me says 'Cygwin GDB GNU gdb (GDB) 7.8' [too many gdb's in that line ;-)]
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
- 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
There should be no errors in the console window. You will see that the 'Run' -> 'Build' option is now active
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
How to Export Templated Classes from a Dll Without Explicit Specification
C++ Short-Circuiting of Booleans
Operator Overloading Outside Class
C++ Access Derived Class Member from Base Class Pointer
Difference Between Returning Reference VS Returning Value C++
Matlab VS C++ Double Precision
Link Errors Using <Filesystem> Members in C++17
How to Truncate a File While It Is Open with Fstream
Class Type Non-Type Template Parameter Initialization Does Not Compile
Setting Vector Elements in Range-Based for Loop
At^Sysinfo and a C++ Terminal Program
Explanation of Function Pointers
Returning to Beginning of File After Getline
Getting a Vector<Derived*> into a Function That Expects a Vector<Base*>