CLion IDE: Downloading, Installing, and Testing


Download/Install/Test the CLion IDE

CLion is an Integrated Development Environment (IDE) that uses the Cygwin toolset to develop/test C++ programs. It occupies about 700 MB on disk.

Before installing CLion in this handout, you should have already downloaded and installed the Cygwin toolset (if you haven't, go back and do so).

You may want to print these instructions before proceeding, so that you can refer to them while downloading and installing CLion. Or, just keep this document in your browser. You should read each step completely, before performing the action that it describes.

This document shows the installation of CLion version 2017.2.2; I installed this version during Summer 2017 (although the Registration part, which I couldn't repeat, was from 2016). You should install the latest version to be compatible with how CLion is used in this document.


JetBrain's CLion: Version 2017.2.2

Section 0) Registering For a Free Copy of CLion

In this section you will register for a free copy of CLion online.

  1. Click Student License.

    When run, the following JetBrains Products for Learning screen should appear. Fill it in as shown, but with your Name and Email address (not mine).

    Click the APPLY FOR FREE PRODUCTS button.

    The following screen may appear.

    If it appears, click the checkbox.

    A Thank You! screen will appear, indicating that Jet Brains is sending you a Confirm Request email.

  2. You should receive an email from JetBrains (likely within 5-10 minues) containing the following text:
    Hi,

    You've received this email because your email address was
    used for registering/updating a JetBrains Educational Pack.

    Please follow this link to confirm your intention:

    Confirm Request

    Yours truly,
    JetBrains Team
    https://www.jetbrains.com
    The Drive to Develop

  3. Click the Confirm Request link. A Congrats! You've been approved! screen will appear, indicating that Jet Brains is sending you an Activate Educational License email.

  4. You should receive an email from JetBrains (likely within 5-10 minues) containing the following text:
    Dear <Your first name>

    Congratulations! Your JetBrains Student License is confirmed.

    To activate your license, use the following link:
    Activate Educational License

    After accepting the License Agreement, you will be asked
    to sign up for a Student JetBrains Account. You will use
    this account to sign in to JetBrains product(s) whenever
    you use them.

    Happy coding!

    Yours truly,
    JetBrains Sales Team
    https://www.jetbrains.com

  5. Click the Activate Educational License link. A TOOLBOX SUBSCRIPTION LICENSE AGREEMENT FOR EDUCATION screen will appear.
  6. Click the I Accept button.

    The following JetBrains Products for Learning screen should appear.

  7. Enter your User Name and Password (and Repeat Password), click the I have read... checkbox, and click the Submit button. Write this information in a location for future reference.

    The following JetBrains Product Pack for Students screen should appear (I have blacked-out my License ID).

    Write down the License ID for future reference.

  8. Note that anyone (even without a university email address) can download a Free 30 Day Trial version of CLion.

Section 1) Downloading/Installing CLion

In this section you will download and begin installing CLion for use with the Cygwin toolset.

  1. Click CLion.

    When run, the following Download CLion screen should appear (ensure the Oval surrounds the operating system you are on).

    Click the Download button to download the executable file named CLion-2017.2.2.exe, which when run will install the 64-bit version of CLion. It may display another screen asking you to enter information; you can enter information on this screen or ignore it. Its icon will appear on your screen as follows.

    Save this file for future use, in case you need to reinstall it: on my system I stored this file as C:\ZData\Installed Software\CLion-2017.2.2.exe

  2. Double-click the CLion-2017.2.2.exe file.

    When run, the following Open File - Security pop-up window should appear on your screen.

  3. Click the Run button on this window.

    When run, the following User Account Control pop-up window should appear on your screen.

  4. Click the Yes button on this window.

    If you have no previous version of CLion installed, the following CLion Setup pop-up window should appear on your screen.

    If you have any previous versions of CLion installed, the following CLion Setup pop-up window should appear on your screen. Check the checkboxes for the versions you want to uninstall, and check the checkbox labelled Uninstall silently.

  5. Click the Next> button on whichever window appeared.

    The following CLion Setup: Choose Install Location pop-up window should appear on your screen.

    For simplicity and consistency, ensure the Destination Folder is C:\Program Files\Jetbrains\CLion 2017.2.2 (the default).

  6. Click the Next> button on this window.

    The following CLion Setup: Choose Installation Options pop-up window should appear on your screen.

    Check all checkboxes (the default is none are checked).

  7. Click the Next> button on this window.

    The following CLion Setup: Choose Start Menu Folder pop-up window should appear on your screen.

    For simplicity and consistency, ensure the textbox contains JetBrains (the default).

  8. Click the Install button on this window.

    The following CLion Setup: Installing progress pop-up window should appear on your screen.

    It might take (a few) minutes (depending on your connection speed) for CLion to be downloaded and installed. Eventually this window will be replaced by the following Cygwin Setup - Installation Status and Create Icons window on your screen.

  9. Click the Finish button on this window (leaving unchecked the Run CLion checkbox).

    Create a shortcut icon (named just CLion) on your desktop to the file C:/Program Files/JetBrains/CLion 2017.2.2/bin/CLion64.exe

    You will double-click this icon to start CLion (see the next section).


Section 2) Initializing/Testing CLion with the Cygwin Toolset and Clang

In this section you will finish installing CLion and then create, build, and run a trivial CLion project/program (including editing it and seeing how syntax errors are reported). It will also discuss some useful features in the CLion IDE.

  1. Double-click the shortcut to the CLion icon that you created above.

    If you have no previous version of CLion installed, the following Complete Installation pop-up window should appear on your screen. Ensure the I do not have... radio button is pressed.

    If you have a previous version of CLion installed, the following Complete Installation pop-up window should appear on your screen. Ensure the Previous version ... radio button is pressed. This configuration information was not removed as part of the uninstall.

  2. Click the OK button on which everwindow appeared.

    If a CLion Privacy Policy Agreement appears, click Accept.

    The following CLion License Activation pop-up window may appear on your screen.

  3. Click the OK button on this window. The following License Agreement for CLion 206.1.3 pop-up window should appear on your screen.

  4. Click the Accept button on this window.

    The following CLion Privacy Policy Agreement pop-up window should appear on your screen.

  5. Click the Accept button on this window.

    The following CLion License Activation pop-up window should appear on your screen.

    --->

  6. Enter your Username or email and Password, and then click Activate button.

    The following Customize CLion UI Themes pop-up window may appear on your screen.

    Ensure the IntelliJ radio button is pressed (the default).

  7. Click the Next: Toolchains button on this window.

    The following Customize CLion Toolchains pop-up window may appear on your screen. The actual version you see may be slightly different (this one appeared with version 2016.3.1).

    Press the Use Cygwin home radio button and ensure C:\cygwin64 is in its textbox (the default). Press the Use bundled CMake 3.5.1 radio button (the default).

  8. Click the Next: Default plugins button on this window.

    The following Customize CLion Default plugins pop-up window may appear on your screen.

  9. Click the Next: Featured plugins button on this window.

    The following Customize CLion Featured plugins pop-up window may appear on your screen.

  10. Click the Start using CLion button on this window.

    The following splash should appear on your screen.

    Eventually CLion loads and the following Welcome to CLion pop-up window should appear on your screen. The actual version you see may be slightly different (this one appeared with version 2016.3.1).

  11. Click the New Project button on this window.

    The following New Project pop-up window should appear on your screen.

    In the Location textbox, at the end of the path, replace untititled by trivialtest; leave the C++ Executable and C++11 selected.

  12. Click the OK button on this window.

    If a Tip of the Day pop-up window appears, click it Close button.

    The following Background Tasks pop-up window should appear on your screen.

    Wait for it to finish all its tasks (a few minutes at most).

    The following CLion project window should appear on your screen.

    Note that the right pane lists the tabs CMakeLists.txt (which contains the project's make code) and main.cpp (which is shown and contains a trivial C++ program). These tabs appear in alphabetical order (and cannot be re-ordered); if you want to be able to reording of these tabs, you can select Window | Editor Tabs and click Sort Tabs by Filename to uncheck this option.

    If we right-click in the gray area between the Project and Editor panes, we can toggle Show Line Numbers and Show Indent Guides options.

    It useful to click the triangle to the left of trivialtest in the Project/left pane.

    Every project will contain a cmake-build-debug folder, which will ultimately contain the compiled code (executable) for the project. Later, we will see how to put data files in that folder; the executable uses that folder by default for reading/writing files.

  13. Depress the File tab and select Settings as shown in the following illustraton.

    The following Settings window should appear on your screen.

  14. Disclose the Build, Execution, Deployment item, and select CMake.

    The following Settings window should appear on your screen (see below for filling in the CMake options textbox).

    Copy and paste the text

    -D CMAKE_CXX_COMPILER=/cygdrive/c/cygwin64/bin/clang++ -D CMAKE_C_COMPILER=/cygdrive/c/cygwin64/bin/clang

    into the CMake Options textbox. These CMake switches tells CLion that we will be using the Clang C++/C compilers. Doing so never will be wrong, but it might be unnecessary if you have only one C++/C compiler on your system.

    Another way to fix this problem is to ensure the following lines start your CMakeLists.txt file (see part 15 below, which shows the last line).

      cmake_minimum_required(VERSION 3.3.2)
    
      project(test_all_data_types)
    
      set(CMAKE_CXX_COMPILER "/cygdrive/c/cygwin64/bin/clang++")
      set(CMAKE_C_COMPILER "/cygdrive/c/cygwin64/bin/clang")
    
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

    If you do have multiple compilers on your machine and forget to specify these CMake switches or CMakeLists.txt options (or enter the wrong information) you might encounter compliation problems. They often contain the text multiple definition of ...

    You will setup all projects in the same way, so once you do a few, all the rest will be setup similarly.

  15. Click the OK button on this window.

    The Background Tasks pop-up window may appear briefly on your screen.

    The following CLion project window should appear on your screen.

    The CMake-Debug pane will appear at the bottom of CLion and various information should scroll through it, ending as shown. It shows CLion checking whether the CMake switches you entered are legal, and updating the cmake-build-debug folder; it may take a few minutes. You can scroll through the CMake pane at the bottom, to see all its information, which appears below.

    If you want to examine the CMakeLists.txt file, click on it (in the right pane). It will update the right pane to

    If you do this, click on main.cpp (in the right pane), to return to the C++ program.

  16. Click the (Build icon) on this window.

    The following CLion project window should appear on your screen.

    The results of the build appear in the Message Build pane. This trivialtest C++ program has now been compiled and linked successfully; either could have dispayed errors in the Message Build pane, which would have to be corrected before the program could be run.

  17. Click the (Run icon) on this window.

    The following CLion project window should appear on your screen.

    The results of running the program print in the Run pane.

  18. To edit, rebuild, and rerun the program, change the output string to "Goodbye, World!" and then click the (Run icon) again. CLion will rebuild the project (which contains no errors; you will briefly see the Message Build pane as shown above), and then rerun it.

    The following CLion project window should appear on your screen.

    The results of rerunning the program appear in the Run pane.

  19. If we create a syntax error (remove the ; at the end of the cout line), CLion will soon highlight the character after endl (where the ; belongs), showa red squiggle under the error, and put a purple an underline at the right end of that column in the main.cpp pane. If we hover over the red squiggle, the main.cpp pane shows

    If we hover over the purple line, the main.cpp pane shows

    CLion will also put a white ! surrounded by a red circle at the end of the top line in the main.cpp pane.

    The following CLion project window should appear on your screen.

    To try to rebuild and rerun this code (it will fail), click the (Run icon) again.

    The following CLion project window should appear on your screen.

    The failed results of attempting to rebuild the program appear in the Messages Build pane; here you can reposition the separation between the mail.cpp and Message Build panes to show the entire program and all the errors allow all errors to appear.

We will now continue by learning how to download a CLion project and run it. During the quarter, you will be asked to do this for all programming assignments and many quizzes.


Section 3) Testing Downloadable CLion Projects with the Course Libraries

In this section you will learn more about CLion, by downloading the course libraries and then downloading/building/running a CLion project that contains various programs that use these libraries.

  1. Create a new shortcut named ClionProjects (to the folder C:\Users\yourname\ClionProjects, which CLion should have creatred, now containing only the trivialtest folder) and place it on your desktop near the shortcut that you use to start CLion.

  2. Download and unzip the file libraries; Copy its three folders (courselib, gtestlib, and test_all_data_types) into the folder ClionProjects shortcuts; it should already contain the trivialtest folder, created by the operations above.

    Generally, whenever you download CLion projects, you will unzip them and then copy their folders into the folder that ClionProjects shortcuts.

  3. Click the File tab near the upper-left corner of the CLion window; then click the Open option in the pull-down menu.

    The following pop-up window should appear on your screen.

    You may need to scroll this window and disclose/undisclose various folders to make it appear as shown above. The Users folder should contain a folder with your name (Pattis for me); it should contain a folder with the ClionProjects folder; it should contain the three folders courselib, gtestlib, test_all_data_types, and trivialtest.

    Click on the test_all_data_types folder, so that it is highlighted.

  4. Click the OK button on this window.

    The following Open Project window should appear on your screen.

  5. Click the This Window button on this window. (clicking New Window creates a second project window, which is sometimes useful)

    The following CLion project window should appear on your screen (after you disclose the test_all_data_types folder).

  6. Scroll downward, select lines 30-35, and press ctrl-/, which uncomments the chosen lines.

    The following CLion project window should appear on your screen.

    If you press ctrl-/ again, it will comment the lines; so this command really means toggle-comment on the selected lines. Before continuing ensure lines 30-35 are uncommented.

  7. See Steps 10-12 (from Section 2) for the pictures of these steps.

    Depress the File tab and select Settings.
    Disclose the Build, Execution, Deployment item, and select CMake.
    Copy and paste the text

    -D CMAKE_CXX_COMPILER=/cygdrive/c/cygwin64/bin/clang++ -D CMAKE_C_COMPILER=/cygdrive/c/cygwin64/bin/clang

    into the CMake Options textbox. Click the OK button on this window.
    The Background Tasks pop-up window may appear briefly on your screen.
    A CMake-Debug pane will appear and fill with information.

  8. Click the (Build icon) on this window The following CLion project window should appear on your screen. It shows the Message Build pane.

    Then click the (Run icon) on this window.

    The following CLion project window should appear on your screen.

    It shows the Run-test_all_data_types pane.

      We could have bypassed the Build icon and just click the Run icon, but it is often useful (esepcially with programs that contain syntx errors) to Build and Run separately. If we clicked Run, CLion would show the Message Build pane; then it would immediately show the Run pane.

    Experiment with this driver by entering commands (and their arguments, when prompted) to better understand the set data type. You can enter the q command to terminate the driver, or you can click the (Stop icon) on the left of the Run pane to terminate the driver. After terminating the driver, click the (Close icon) left of the Run pane to close/remove the Run pane.

    I suggest that you try terminating the driver with a q command; then, rerun the program and terminate it with the Stop icon.

  9. We briefly noted the cmake-build-debug folder; now we will examine it in more detail, but via an Explorer window, not via CLion. Click on the ClionProjects shortcut to open an Explorer window, then double-click its test_all_data_types folder, and finally double-click its cmake-build-debug folder.

    The following Explorer window should appear on your screen.

    Whenever you create a project, a cmake-build-debug folder will appear in its project folder. We have built two projects in this handout: test_all_data_types and trivialtest; each has its own cmake-build-debug folder.

  10. Double-click the file test_all_data_types.exe in this folder to run this program in Windows, outside of CLion. The following MS-DOS window should appear on your screen.

    If the error pop-window

    appears, you must also add C:\cygwin64\bin to the user variable PATH, briefly illustrated below (also see step 15 in the Cygwin handout).

    Experiment with this driver by entering commands (and their arguments, when prompted); it runs as it did in the CLion Run pane. Note that when you enter the q command the program terminates and the MS-DOS window immediately disappears.

    So, when a program we run under CLion terminates, its Run pane retains the information printed (by cout) after the run terminates, but when we run it directly in an MS-DOS window, the window disappears after the run terminates. For example, if you find the trivialtest.exe file and run it by double-clicking this file, its MS-DOS window will run and then immediately disappear.

    For a program that produces lots of output and does not terminate (we can always put an input statement at the end, so it doesn't terminate until the user enters something) it is often faster to run the program in an MS-DOS window, rather than in CLion.

  11. Find the input files folder in the test_all_data_types folder and copy all of its .txt data files into the cmake-build-debug folder that contains the test_all_data_types.exe file. Copy these files using an Explorer window or the Project pane in the CLion window (after disclosing the cmake-build-debug and input files folders).

    The following Explorer window shows what the cmake-build-debug folder should contain.

    Then, run the program (either in the CLion Run pane or a MS-DOS window; try doing it from both places) and issue the lf command (load from file); when prompted for the file name, just press the Enter key to choose the default (loadset.txt).

    When running using the CLion Run pane, the following CLion project window should appear on your screen.

    IMPORTANT: If a program reads data files, the root folder for the specifying the files is the folder in which the .exe file appears. It is simplest to copy all the data files into this folder. An alternative would be to leave the files in the input files folder, copy the entire folder, and then refer to these file names like input files\loadset.txt.

  12. A typical project folder may have more than one .cpp file with a main function (as test_all_data_types has). Only one of these .cpp files can have its main function uncommented, otherwise the build will fail. When working on project, it is typical to

    1. Comment-out code in one .cpp file.
    2. Uncomment code in another .cpp file.
    3. Rebuild/Rerun the newly uncommented .cpp file.

    In the test_all_data_types project folder, the driver.cpp file has many main functions: we uncommented one (in step 6 above) to allow us to run the Set driver. If more than one main function is uncommented, attempting to build the code will result in the compiler specifying a redefinition of 'main' error.

    The test_all_data_types project folder also contains many .cpp files (their names all start with test) that each contain one main function (each is a Googletest for one data type). If more than one file contains a main function, attempting to build the code will result in the linker specifying a multiple definition of 'main' error.

    To switch this project from running the Set driver to the Set Googletest

    1. Comment-out lines 30-35 in the driver.cpp file: select them and type the ctrl-/ command to toggle the commenting on the selected lines (comment them).
    2. Scroll down the Project Pane (on the left) and double-click the test_set.cpp file so that it appears as an editor tab.
    3. Type the ctrl-a command to select all the lines in this file.
    4. Type the ctrl-/ command to toggle the commenting on the selected lines (uncomment them).

    Click the (Run icon). When prompted enter the three lines of information shown.

    The following CLion project window should appear on your screen.

    ICS-46 will provide Googletests like these for many programs, much as ICS-33 proivded batch self-check files: so you will automatically receive feedback on the correctness of your code.

We are now at the end of this handout. You will not need to repeat the first two sections during the course, but you will frequently download project folders and use them as demonstrated in section 3.