CLion 2019.1 Help

Quick Start Guide

This Quick Start Guide is designed to introduce the key concepts and help you make a quick start with the IDE.

Step 0. Before you start

What languages does CLion Support?

With CLion, you can develop applications in C and C++. Besides, it fully supports Objective-C/C++, HTML (including HTML5), CSS, JavaScript, and XML: these languages are bundled in the IDE via plugins and are switched on by default. See CLion Features in Different Languages for more details.

Support for other languages can also be added via plugins (go to Settings / Preferences | Plugins to find out more and set them up).

What platforms can I run CLion on?

CLion is a cross-platform IDE that works on Windows, macOS, and Linux.

Which compilers are supported by the IDE?

CLion supports GCC, Clang and Microsoft Visual C++ compilers.

What do I need to start with CLion? What are the system requirements?

In general, to develop in C/C++ with CLion you need:

For debugging, CLion bundles GDB (on Windows, the bundled GDB is available only for MinGW) and LLDB (on Linux and macOS), so you don’t need to install them separately unless you want to use a custom version instead of the bundled one. Currently, the versions of the bundled debuggers are:

  • LLDB v 7.0.1

  • GDB v 8.0.1 for macOS

  • GDB v 8.2 for Windows

  • GDB v 8.2 for Linux

  • For a custom GDB, CLion supports versions 7.8.x-8.2.x

CMake is also supplied with CLion, and you can check the number of the bundled version in Settings / Preferences |Build, Execution, Deployment | Toolchains under the CMake field.

For the general system requirements, refer to the Install and Setup guide.

What project formats are supported?

CLion supports CMake, Gradle, and compilation database projects. CMake projects can be created, opened, built, and run. For Gradle, the available actions are opening projects and running gradle tasks. Compilation database projects can be opened and managed as well, plus you can create custom build targets, which employ external tools to build/clean your project, and add Run/Debug configurations associated with custom targets.

Step 1. Open/Create a project

Open an existing project

For CMake projects, use one of the following options:

  • Select File | Open and locate the project directory. This directory should contain a CMakeLists.txt file.

  • Select File | Open and point CLion to the top-level CMakeLists.txt file, then choose Open as Project.

  • Select File | Open and locate the CMakeCache.txt file then choose Open as Project.

To open a compilation database or Gradle project, point CLion (File | Open) to compile_commands.json or build.gradle or file, and select Open as Project.

Check out a project from Version Control

You can also download sources from a VCS storage or repository. Click Checkout from Version Control on the Welcome screen, or VCS | Checkout from Version Control on the main menu, and select your version control system. Enter the credentials to access the storage, and provide the path to the sources. CLion will clone the repository to a new CMake project.

Create a project from scratch

To start a new CMake project, click File | New Project from the main menu New Project or the Welcome screen, select the project type, the root folder location, and the C/C++ language standard. CLion will create a new project and fill in the top-level CMakeLists.txt. A sample project will have the following structure:

Creating a project form scratch

Step 2. Take a look around

When you launch CLion for the first time, or when there are no opened projects, you see the Welcome screen. It shows the main entry points to create or open a project, get help, and configure the IDE:

welcome screen

When a project is opened, you can see the main window divided into several areas. Let’s take a moment to view the key UI elements:

Look around
  1. Project view on the left side displays the project files and directories.

  2. Editor is the area where you can view, write, and edit your code. The editor shows each code file in a separate tab, and also it can be split verticallyicons actions splitVertically svg or horizontallyicons actions splitHorizontally svg for easier navigation between tabs.

  3. Navigation bar is there for quick access to the run/debug and VSC-related actions.

  4. Left gutter, the vertical stripe to the left of the editor, shows breakpoints and provides a convenient way to navigate through the code structure (for example, jump to a definition or declaration).

  5. Right gutter shows the results of the code analysis performed by CLion as you type. A square sign at the top of the right gutter indicates the overall analysis status for the whole file.

  6. Tool windows are specific windows dedicated to project structure, CMake, terminal, and other IDE tools.

  7. Status bar shows various indicators for the project and the entire IDE: file encoding, line separator, inspection profile icons ide hectorOn svg, memory indicator, and so on. Also, here you can find the resolve contexts switcher.

Step 3. Customize the environment

The quickest way to switch between the IDE's color schemes, code styles, keymaps, viewing modes, and look-and-feels (UI themes) is the Switch... pop-up. To invoke it, click View | Quick Switch Scheme or press Ctrl+Tab:

switch pop-up

The Settings / Preferences menu gathers the IDe- and project-level settings that you can customize. A few examples are given below.

Appearance

The first thing to fine-tune is the general "look and feel." Go to Appearance and Behavior | Appearance to select the IDE theme: IntelliJ light theme, Darcula, or High Contrast.

Editor

Pages under the Editor node help you adjust every aspect of the editor’s behavior, from general settings (like Drag'n'Drop enabling and scrolling configuration) to highlighting colors and code folding options.

Code style

Code style can be defined for each language in Editor | Code Style, applicable to a project or the entire IDE depending on the selected Scheme. For C/C++ code, you can configure Naming conventions or use a predefined code style.

Keymap

CLion is keyboard-centric: nearly all actions possible in the IDE are mapped to keyboard shortcuts or, in case something is missing, you can map actions manually. CLion provides a rich default keymap (explore it in the Help | Default Keymap Reference menu). To customize it, go to Settings / Preferences| Keymap where you can choose one of the pre-defined keymaps (Emacs, Visual Studio, Eclipse, NetBeans, Xcode, and others) or create your own.

Step 4. Code with smart assistance

CLion takes care of the routine so that you can focus on the important. Below are some examples of CLion's code insight features for error-free and productive development.

Code completion

Code completion is a great time-saver, regardless of the type of file you are working with. There are two types of code completion in CLion: basic (Ctrl+Space) and smart (Ctrl+Shift+Space). Basic completion works as you type and completes any symbol instantly. Smart completion analyzes the context and offers more accurate suggestions based on that analysis. For example, it filters the list of functions and variables to match the expression type:

cl QST smartCodeCompletion

Code generation

Writing code can be a lot easier and quicker with code generation. The Code | Generate menu (Alt+Insert) will help you with constructor/destructor or getter/setter generation and will suggest overriding (Ctrl+O) or implementing (Ctrl+I) functions:

cl QST impl over

To generate entire code constructs, use live templates (call Code | Insert Live Template or press Ctrl+J). You can explore and extend the list of the ready-to-use templates in Settings / Preferences | Editor | Live templates.

Also, consider quickly surrounding your code with complete constructs like if, while, for, #ifdef, and other wrappers, depending on the context. Call Code | Surround With or press Ctrl+Alt+T: for example, select an if statement

cl QST surround with 1
and you will get
cl QST surround with 2

Intention actions

CLion monitors your code as you type and makes smart suggestions called intention actions. Indicated with a yellow light bulb icons actions intentionBulb svg, intention actions enable you to apply automatic changes to the code that is correct (in contrast to code inspections that provide quick-fixes for the code that might be incorrect). As an example, when a constructor misses some parameters or field initializers, CLion suggests an intention for this situation (click a light bulb or press Alt+Enter):

intention actions
Find the full list of the available intentions in Settings / Preferences | Editor | Intentions.

Step 5. Keep your code neat

CLion monitors your code and tries to keep it accurate and clean. It detects potential errors and problems and suggests quick-fixes for them.

Every time the IDE finds unused code, an endless loop, '=' in a conditional expression, or some other error-prone piece of code that likely require your attention, you’ll see a red light bulb icons actions quickfixBulb svg. Click it or press Alt+Enter to apply a fix:

cl QST inspection
Find the complete list of the available inspections in Settings / Preferences | Editor | Inspections. You can disable/enable inspections and configure their severities (whether you want it to be shown as error or warning) and scopes.

Step 6. Find your way through

CLion comes with a set of navigation features that will help you find your way through any codebase.

Basic search

To find where a particular symbol is used, use full-scale search via Find Usages (Alt+F7):

Find usages
You also have the option to search only in the current file (Ctrl+F), or within a directory, any arbitrary scope, or the entire project (Ctrl+Shift+F).

Code navigation

To navigate through the code structure, use the following Go-To's:

Icons in the left-hand gutter can also help you with code navigation:
cl QST goToSubclass

Search Everywhere

To search for anything in CLion, be it an item in your codebase, user action, or UI element, press Shift twice and start typing what you are looking for in the Search Everywhere dialog. For example, you can search for an IDE action:

search for an ide action

Navigate through the timeline

In CLion, you can easily navigate you to the recent files (Ctrl+E) or recently changed files (Shift+Alt+C). To explore the history of changes, use Back/Forward navigation (Ctrl+Alt+Left/Ctrl+Alt+Right) or jump to the last edit location (Ctrl+Shift+Backspace).

Step 7. Configure the CMake build system

For CMake projects, CLion takes all the information about the project from the CMakeLists.txt files. Every change you make in CMakeLists.txt requires project reload. It can be performed automatically (select the corresponding checkbox in Settings / Preferences | Build, Execution, Deployment | Cmake) or you can call Tools | CMake | Reload CMake Project.

To learn more about configuring CMake in CLion, take a look at our CMake Tutorial.

Step 8. Run and debug

Run/Debug configuration

For running and debugging your applications, CLion uses Run/Debug Configurations.

To create new configurations, use the predefined templates (for a regular application, remote debug, unit testing, and others). You can find the available templates and edit existing configurations in the Edit Configurations dialog accessible from the Run menu or the configuration switcher:

configurations editor

Debug

CLion bundles the GDB debugger for macOS, Linux, and Windows (in case of MinGW only), and the LLDB debugger for macOS and Linux. Also, you can use custom GDB on all the platforms.

Debugging almost always includes placing breakpoints: click the left gutter of the line where you want the breakpoint to appear. To start a debug session, select the desired Run/Debug configuration, and press Shift+F9 or click icons actions startDebugger svg. Then you can follow through the execution step by step (see the available options in the Run menu or the Debug tool window), evaluate an arbitrary expression, add watches and manually set values to the variables:

Debugging

Step 9. Keep your code under Version Control

VCS

CLion integrates with several version control systems: Git (or GitHub), Mercurial, Perforce, Subversion, and TFS. To specify credentials and control the settings of a particular VCS, go to Settings / Preferences | Version Control.

In the VCS menu, you can find the available commands: for example, to view the changes and commit them, create changelists, and much more. Also, some basic commands are accessible from the Navigation bar above the editor:

vcs command in navigation bar

Local history

In addition to version control, you can use the local history enabled by default. To view it for a file or a folder, call VCS | Local History | Show History. Here you can review the changes, revert them, or create a patch.

Step 10. That’s it! Go ahead and develop with pleasure!

We hope this brief overview of the CLion essentials will give you a quick start. There are many features that make a developer’s life easier, and your code neater and cleaner. Take these first few steps now, and then dig deeper when you feel the time is right. Enjoy CLion!

With any questions, feel free to ask on the CLion Discussion Forum. Also take a look at our twitter and blog, where you can find news, updates, and useful tips and tricks. And don't hesitate to report any problems to our support team or the CLion issue tracker.

Last modified: 22 April 2019