On Windows, configuring CLion requires setting up the environment: Cygwin, MinGW, WSL, or Microsoft Visual C++. You can have several environments installed on your system and create separate CLion toolchains for each of them. As a determining part of a toolchain, the environment provides C and C++ compilers, the make utility, and the debugger (in case of using default tools).
CLion produces a CMakeLists.txt file when you create a new project. In that file, you must set your compiler version and compiler directives just as you would via terminal. Here is an example of a CMakeLists.txt file used to compile an OpenGL project (this is running on OS X, so flags will be different if you’re using another operating system). 9th September 2020 c, clion, glut, opengl, windows. Can’t understand what’s wrong at all I have installed OpenGL and Glut from different tutorials, but when. When you create a new project, CLion generates CMakeLists.txt file automatically and places it in the project root directory. To open a project, you can point CLion to the top-level CMakeLists.txt and choose Open as Project. Example below shows the CMakeLists.txt file of a simple 'Hello, World!'
Linux has made it easier to use OpenGL than Windows. Cmakeminimumrequired(VERSION 3.10) # common to every CLion project project(OpenGLLinuxTest) # project name set(OpenGlLinkers -lglut -lGLU -lGL) # setting all the Glut libraries as one variable. CLion is also available as a snap package. If you’re on Ubuntu 16.04 or later, you can install CLion from the command line. Sudo snap install clion -classic.
For details on Remote Host toolchains, see Full Remote Mode.
MinGW-w64 (64- and 32-bit)
Download and run the MinGW-w64 installer. It provides both 64- and 32-bit options.
In the MinGW-w64 installation wizard, make sure to select the required architecture. Note that the default suggested option is 32-bit.
Once the installation is finished, open CLion and go to File Settings Build, Execution, Deployment Toolchains.
Choose the MinGW toolchain that you want to configure or create a new one using the icon.
CLion will attempt to detect the MinGW installation automatically. Check the detection result in the Environment field, and specify the path manually if required.
Wait until the tools detection finishes.
Select the Debugger: you can use either MinGW-w64 GDB or a custom GDB binary.
Click Apply when all the tools are set correctly.
Although MinGW-w64 provides both 64- and 32-bit options, you can also install MinGW, the 32-bit-only version.
Clion Opengl 2
In the MinGW installation wizard, select the following packages from the Basic Setup list: mingw-developer-tool, mingw32-base, mingw32-gcc-g++, mingw32-msys-base.
- Follow the steps 3-7 for MinGW-w64.
When configuring the toolchain, if CLion cannot detect compilers or make, double-check the installed packages in MinGW Installation Manager.
In the Debugger field, you can choose between the bundled GDB, MinGW GDB, or your custom GDB executable.
The recommended option is bundled GDB, since it is guaranteed to include Python support required for CLion data renderers.
Download the Cygwin installer, version 2.8 or later.
Run the installer and select the following packages:
To select a package, type its name in the Search field and then click it in the list until a tick mark appears in the Bin? column:
Once the installation is finished, open CLion and go to File Settings Build, Execution, Deployment Toolchains. Choose the toolchain that you want to configure.
Select Cygwin from the Environment list. CLion will attempt to detect the Cygwin installation automatically. Check the detection result, and specify the path manually if required.
Wait until the tools detection finishes, and press Apply.
Windows Subsystem for Linux
Clion Opengl 3
You can use WSL, Windows Subsystem for Linux, as your working environment in CLion on Windows 10 (starting the Fall Creators Update version 1709, build 16299.15).
WSL toolchain enables you to build projects using CMake and compilers from Linux and run/debug on WSL without leaving CLion running on your Windows machine.
Refer to our WSL guide for details on setting up WSL on your system and configuring WSL toolchains in CLion.
Microsoft Visual C++
Install Visual Studio 2013, 2015, 2017, or 2019 on your system.
In CLion, go to File Settings Build, Execution, Deployment Toolchains.
Click and select Visual Studio from the list of toolchain templates.
Check the Environment field. CLion will attempt to automatically detect the installed Visual Studio distribution. If the detection fails, set the path to Visual Studio manually.
If required, specify the Architecture (x86, amd64, x86_arm, or another), Platform (store, uwp, onecore, or leave it blank), and Version. To build your project for the selected architecture, CLion will call the script to configure the environment with the specified parameters.
If the version of your compiler toolset is earlier than the version of your Visual Studio installation, pass it in the Version field via the
vcvars_verflag, for example,
Wait until the tools detection is finished:
CLion supports the Microsoft Visual C++ compiler that ships with Visual Studio 2013, 2015, 2017, and 2019.
Note that msbuild is not supported: CLion runs CMake with the NMAKE generator instead.
For the case when your code includes MSVC extensions, CLion provides the support for:
pointer type attributes:
MSVC built-in data types:
additional format specifiers, such as
the clang 's
As an alternative compiler, you can use clang-cl- the MSVC-compatible compiler driver for Clang. CLion supports clang-cl version 8.0 and later.
Install clang-cl from the LLVM site or along with the Visual Studio tools.
When installed from the LLVM site, the clang-cl binary can be found at the standard location C:Program FilesLLVMbinclang-cl.exe for the 64-bit version or C:Program Files (x86)LLVMbinclang-cl.exe for the 32-bit version.
In CLion, go to File Settings Build, Execution, Deployment Toolchains and select the Visual Studio toolchain that you want to configure, or create a new one.
Point the C Compiler and C++ Compiler fields to clang-cl.exe. CLion will suggest the paths detected automatically.
Note that currently the
-T clangcl options can't be picked up if the bundled CMake is in use along with the Visual Studio toolchain setup (CPP-18848 ).
LLDB-based MSVC debugger
The MSVC toolchain debugger is implemented on top of LLDB. It can work with native visualizers from the Visual Studio installation or from your project. To enable native visualizers support and set the desired diagnostics level, select Enable NatVis renderers for LLDB in Settings Build, Execution, Deployment Debugger Data Views C/C++:
Also, if you have custom native visualizers in your project, CLion will use them as well:
Clang compiler on Windows
With CMake 3.15, it has become possible to use the Clang compiler on Windows with the MinGW-w64/MinGW toolchain.
However, the LLVM Clang for Windows is built using Microsoft Visual Studio, and all the built-in macros and include search paths are set up for use with Visual Studio. So if you take Clang from the LLVM repository, it will not work correctly when configured with the MinGW toolchain. One of the possible workarounds is described below.
Set up the Clang compiler for MinGW
Download the following packages with the pacman tool (use the
pacman -S package_namecommand):
This way, you will get the Clang compiler which is built with mingw-w64 and has paths and macros that correspond to this toolchain.
Go to Settings / Preferences Build, Execution, Deployment Toolchains, create a MinGW toolchain, and set up the tools from MSYS.
After specifying the Environment, check the automatically detected tools and make sure to switch to Clang in the C Compiler and C++ Compiler fields.
With this new toolchain configured, you can build the project and start using the Clang's advances tools, such as profile-guided optimization. Take a look at our detailed blogpost for instructions.
GDB on Windows
In the case of MinGW, CLion includes the bundled GDB (version 10.1). For Cygwin, you need to install the GDB package in the Cygwin Package Manager, as described in the Cygwin section of this guide.
You can also switch to a custom GDB binary. In this case, the supported GDB versions are 7.8.x-10.1.
Note that for GDB 8.0 and later, debugger output is redirected to CLion console by default. To enable opening an external console window for application input/output, go to Help Find Action or press Ctrl+Shift+A, search for Registry, and set the following key: cidr.debugger.gdb.workaround.windows.forceExternalConsole.
CMakeLists.txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both).
When you create a new project, CLion generates CMakeLists.txt file automatically and places it in the project root directory. To open a project, you can point CLion to the top-level CMakeLists.txt and choose Open as Project.
Example below shows the CMakeLists.txt file of a simple 'Hello, World!' project:
You can edit CMakeLists.txt files right in the Editor. Make sure to reload the project after editing. Automatic reload feature is disabled by default, you can turn it on by selecting the Automatically reload CMake project on editing checkbox in Settings / Preferences Build, Execution, Deployment CMake.
For projects with complex structure, you can create subdirectory CMakeList.txt files to describe the build, contents, and target rules for a subdirectory. Type of a target added by a subdirectory CMakeLists.txt file can differ depending on the role of the module.
Clion Opengl Game
CLion provides code assistance in CMakeLists.txt files. Also, you can configure code style settings for this file format in Settings / Preferences Editor Code Style CMake.