♦ πŸ† 2 min, 🐌 4 min

C++: CLion, The Editor

So far we covered C++ Hello world example, How C++ compiler works, How build system Cmake works and have all building blocks in place to start using one of the most powerful editors for C++: The CLion, brought to you by the team at JetBrains. (For the record they don't pay me to advertise their editors. I just really like them πŸ˜‰).

CLion is a C++ interactive development environment (IDE) created by JetBrains that's so smart it will teach you how to write better more, readable code. It can even catch any redundant object copies and so much more.

JetBrains has other editors for pretty much every possible language out there, and all of them are insanely powerful.

One big issue of CLion is that it works only with C++ projects with existing cmake files. If the project is small, you can write the cmake files pretty quickly and get access to a powerful toolchain with minimal effort. If the project is large and uses another build system, that could be a deal-breaker.

Get the tool

CLion has no free community edition as PyCharm does.

If you're a student or an academic, you can also get the professional licence for free.

Get the version of the software here .

Or install CLion with a package manager on macOS:

brew install clion

Find the app and start it up:

You'll be greeted with the following prompt:

How to use CLion?

How to create a new project in CLion?

You can use the New project option:

Fill out the project's location and the C++ standard that you want to use. Or you can import/open an existing project from your disk.

I prefer to start project structure through the command line using mkdir, touch, ... and then just open the project in CLion. For some reason, I find it more manageable.

Although if you're using the editor for the first time, create a new project with CLion directly to get the feeling for the editor.

How to compile the C++ program in CLion?

With one press on a green fancy button that allows you to "play" or execute the script:

Once you press play, two things will happen. First CLion will use cmake to build and compile your program:

Then it will run the executable in the second step:

The extremely nice part with CLion is that you can execute:

mkdir build
cd build
cmake ..
make

With a press of one button every time you need to rebuild your codebase. So helpful when you want to focus on some wired memory management.

In the above example, the IDE configured the build process and executable to run for us, but sometimes we have an existing project.

Setup the build tools

Sooner or later, you'll have to import an existing project and set up the build environment for it.

Go to the top right corner:

select the executable you want to run, and this UI will open:

This should be self-explanatory.

Split view, tabs

Split views and tabs are pretty cool:

Autocomplete, syntax highlighting, code collapse

You have out of the box code completion at your fingertips:

You can collapse parts of the code to focus only on the part you're working on. Supper useful for longer scripts.

Git mode

On the left-hand side next to each line number, you can see the code changes that are new and still uncommitted.

You can also perform the git branch comparison, ...

Vim mode

Yes, you can set up the vim mode. Customisation is not as easy and versatile like in the command line, but it's really powerful.

Few words on cmake

CLion uses cmake but creates a custom folder where it places all the files generated during the compile process. Those files are placed into cmake-build-debug folder instead of the build one we used in the command line compile process ( How build system Cmake works? ).

cmake-build-debug has the following content:

You should know where those files are and that you can omit them from the version control, but don't dig into this stuff unless you know what you're doing.

Use cmake as a black box as long as you can afford. Then maybe once you master C++ enough you'll want to dig into the anatomy of the build system.

Wrap up

There are so many other features in CLion that it doesn't make sense to cover them here. But in general, the tool can do a lot. If you write C++ daily, use it and never look back.

Get notified & read regularly πŸ‘‡