Installing CLion

There are many tools available for learning how to build programs on your personal computer. The problem I face in teaching this class is helping students do the projects on the machines they happen to own. More and more that means helping students who do not happen to own a Windows PC.

In the past, we have used Dev-C++ almost exclusively for this course. Unfortunately, that tool is Windows only. There are several other tools available, but none work well on all platforms.

In my quest to find one tool all students can use, I came across the CLion product. This is a Java-based application offered by the JetBrains company, which sells the product as a commercial program. The price is pretty high, but they are now offering free licenses to students. In fact, when you sign up with them, they let you install all of the products they sell, and they have an interesting set of offerings for all kinds of developers.

The CLion tool is a full featured IDE for developing several kinds of software products, including C++, which is just what we need. It is not aimed at beginners, meaning some of the ways you have to use this will not be simple for a beginner, but I will keep the need for doing anything difficult to a minimum.

Let’s give it a try!

Sign up on Jetbrains

We need to get you signed up as a student to use the package.

First, open up this link:

Click on the “Buy” tab, then select “Student Licenses”. Next, click on “Apply Now” and fill out the form. You must use your ACC email account to get this free license.

Once the form is complete, click on “Apply for Free Products”. You will get an email with a link to activate your license. After that has been done, you can download any JetBrains product you like.

Download CLion

Back on the JetBrains website, click on the “Tools” menu item. You will see a list of products offered by the company. Select “CLion”.

On this page, click on the “Download” button. On the next page, select your operating system and download the program. This should match your system. The file name I saw when installing this program was:

  • CLion-2017.3.3.dmg (on Mac)
  • CLion-2017.3.3exe (On Windows)

Save this file on your system.

Installing the Program

Once the file is on your system, installing it is as simple as double-clicking on the file name using your file explorer tool. That will start the installation program. Follow the instructions and the program will install normally. (It may take a few minutes to complete. On my Mac, it was pretty quick!).

Warning

On my PC, there were pop-ups asking if I wanted to associate file extensions with this program. I do not do that, since I normally open up program files in my favorite Programmer’s Editor (Vim), not an IDE. If you think this would be useful to you, feel free to set this up, Then, when you double click on a file name in your file explorer tool, that file will automatically open up in CLion.

You might find exploring the JetBrains site for more information about this tool helpful. There are guides, demos, and other resources available. (Just be warned, they are not aimed at beginners. YMMV!)

Installing a Compiler

Unfortunately, CLion does not come with a compiler. Actually, this is not a bad thing. It will use whatever compiler you want. What that means is that we have to make sure we have a compiler installed before we can do much programming.

Windows Compiler

I recommend the MinGW-64 package for the PC. This is a set of tools for developers that were originally created in the Linux world, then ported to the PC. They are professional grade tools. Here is the link for the PC:

Click on this link to download the installer.

Once the installer is on your system, run it to complete the installation

Then open up the CLion application, as described below.

Mac Compiler

To run CLion on a Mac, you will need to install Xcode, which you can do using the “App Store”. This is a big package, and it will take a while to install, but it is essential to doing any programming on the Mac.

Once this is installed, start up CLion and it should find the compiler automatically.

Testing with Hello World

In keeping with tradition, we will test this tool by building a “Hello World” application.

Open the Program

Start the program using your usual scheme. The first time you open this program up, you might be asked if you want to import settings. Since we have no such things around, make sure the “Do not import settings” check box is clicked, and click on “OK”.

Next accept their Privacy Policy.

Now for the important part:

You need to select how you will use this program. You can either run it for 30 days as a demo, or activate it using the license you should have.

Select the “Jetbrains Account” option, then enter your user name and password (you set up earlier, after activating your student license).

Click on “Activate” and your installation be ready to run.

After Activation is complete, you get to select a “Theme”. I like light backgrounds, but you get to pick. (You can always change this later).

Start a C++ Project

Once the program is running, you need to create a new “Project”

  • Select “File->New Project”
  • Make sure C++11 is set as the language.
../_images/Hello01.png

Save the Project

It is important that you control where your projects live. Every tool like CLion thinks they have the right idea where to put things. I never leave this decision to any program. I like to organize my files in a way that helps ME find things. For school, I set up a folder for each class, then under that folder, I create another folder for each project. You can see where I decided to put this example project from the top line in this image:

../_images/hello02.png

You dhould change the path for this project (at least change the “untitled” to something logical, like “HelloWorld”. I choose to keep my projects in a class folder named “cosc1315”)

  • Click on “Create” to build this project

Once the project is ready, you should see a basic “Hello, World” program in the edit window.

../_images/hello03.png

If you compare this example program with examples you find in the book, there is one big difference right away.

A typical “Hello World” example will look like this:

#include <iostream>
using namespace std;

int main(int argc, char *argv[]) {
    cout << "Hello, World!" << endl;
}

Notice that the CLion sample program does not include the “using namespace std;’” line. Leaving that line out means we have to “qualify” both cout and endl, sd shown in the CLion code. Since most examples in the book include that line, change this if you like. The compiler will tell you if somehing is wrong.

Warning

You are going to be shocked when you start seeing the error messages the compiler generates. I am convinced the writers of that program never actually met a real human being, much less anyone who understands their messages. The best we can do is study the messages and try to find a clue as to what went wrong.

My “Baby Step” approach to programming helps here! , free to change this so it looks like the notes. You need to explore the editor in this program anyway.

On the left side is a navigation panel. Click on the small triangle next to the “HelloWorld” line and you will see a list of all files in the project folder. Your code is in “main.cpp”.

Note

When you work on programming projects for this class, you will need to submit the file containing the code you wrote. Do not submit any files I give you (graphics fies, for example). I already have them on my grading system.

If you decided where to put this project, as I suggested, finding the file to submit will be easy. It will end with .cpp.

In the list fo project files, you will see one names CMakeList.txt. This file is important. CLion uses a standard software tool named CMake to build your program (it comes with CLion). That file is a text file used to control how your program is compiled. We will need to work on that file in our graphics labs, in fact, I will provide a complete replacement for this file so you can work those labs. For now, peek at the file by double clicking on its name. The edit window will show this file in a new tab. You can return to the program by click on the tab with the desired file name.

Build Your Program

On the menu at the top, click on “Run -> Build”. You may be asked to do a bit of setup. If you see a form asking for the “Executable” name, select your project name. This will be the name used on the executable file the compiler will build. After finishing this form, the compiler will process your code.

../_images/hello04.png

This will compile your program. If there are no errors, you can click on the “Run->run” menu item to run your code. You will see the output in the bottom window. Any error you encounter will be displayed here as well.

If you get this far, you are ready for standard “console applications” that display text on the screen. To do some fun graphics labs, you will need to do a bit more work. We will get to that after the first exam.