Restart CLion and check 'Settings' - 'Build, Execution, Deployment' to make sure CLion has picked up the right versions of Cygwin, make and gdb Check the project configuration ('Run' - 'Edit configuration') to make sure your project name appears there and you can select options in 'Target', 'Configuration' and 'Executable' fields. This software can also load registry keys from Windows installations on other drives (tools Load Hive). Listed our Windows 10 Pro install as Enterprise. Find your key from outside Windows. CLion keeps regenerating iml module file: Code Analysis. Inspection: Bug: IDEA-242690: Intention to open inspections options doesn't work from Problems view: Bug: IDEA-243833: Inspection widget: the Highlight dropdown disappears on hover: Bug: IDEA-45865: Invalid property key: problems with highlighting on warning and info levels: Bug: IDEA-243718. If you have settings you want to keep, like fonts, colours, inspections, etc, you wan to keep. Goto File Export Settings and save the settings.jar to your desktop.
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 920 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 2019.2; I installed this version during Summer 2019 (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 2019.2
Section 0) Registering For a Free Copy of CLion
In this section you will register for a free copy of CLion online.
Clion License Key
You will ultimately need to provide a copy of your student ID or an unofficial transcript by attaching it when prompted for an OFFICIAL DOCUMENT: you need to provide some 'proof' that you are currently enrolled at UCI. My students have been using CLion for a few years and I have yet to hear of any unresolved problems involving proving they are UCI students.
- 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.
- 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 - 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.
- 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 LicenseAfter 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 - Click the Activate Educational License link. A TOOLBOX SUBSCRIPTION LICENSE AGREEMENT FOR EDUCATION screen will appear.
- Click the I Accept button.
The following JetBrains Products for Learning screen should appear.
- 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.
- 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.
- 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-2019.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:ZDataInstalled SoftwareCLion-2019.2.exe
- Double-click the CLion-2019.2.exe file.
When run, a User Account Control pop-up window may appear on your screen. I could not capture its image, but it asks, Do you want to allow this app to make changes to your device
- 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.
- 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 FilesJetbrainsCLion 2019.2 (the default).
- 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).
- 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).
- 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 CLion Setup - Completing the CLion Setup Wizard window on your screen.
- Click the Finish button on this window (leaving unchecked the Run CLion checkbox).
Find the JetBrains CLion 2019.2 shortcut icon on your desktop.
If there none, create a shortcut icon (with this name, or just CLion) on your desktop to the file C:/Program Files/JetBrains/CLion 2019.2/bin/clion64.exe.
You will double-click this icon to start CLion (see the next section).
Note, when I downloaded CLion I did not need to reboot to complete the installation of CLion; certainly to be safe you can reboot your machine now.
Section 2) Initializing/Testing CLion with the Cygwin Toolset and Clang
Clion License
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.
- Double-click the CLion shortcut icon created above.
On my machine it takes about 15 seconds for the flash screen to appear, and another 5 seconds for the IDE to display.
NOTE: The two icons below are from an older version of JetBrains, so the ones you see may differ.
If you have no previous version of CLion installed, the following Complete Installation pop-up window should appear on your screen. Ensure that 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.
- Click the OK button on whichever window appeared.
The following CLion License Activation pop-up window may appear on your screen.
If it appears, fill in your email and password (see step 6 from 'Section 0') and then click Activate.
- The following CLion User Agreement pop-up window should appear on your screen.
- Scroll throught and read this document :)
Click the I confirm that I have read and accept the terms of this User Agreement box.
Click the Continue button.The following Data Sharing pop-up window should appear on your screen.
- Click the Send Usage Statistics button.
CLion loads and the following Welcome to CLion pop-up window should appear on your screen.
- Click the New Project text 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.
In the Language Standard pull-down list, select C++11. When you create later projects, this will become the new default.
- Click the Create button on this window.
If a Tip of the Day pop-up window appears, click its Close button; you can first check the box to not display such tips in the future.
The IDE's pop-up window will appear. There will be some activity at the bottom (see picture below).
This happens whenever a new project is loaded. Wait for it to finish all its tasks (a few minutes at most).
At that time I saw a window insert (lower-right) that said
I clicked Fix and saw a window that said
I clicked Configure Automatically and saw a window that said
The following CLion project window should appear on your screen I have resized it below).
Note that the right pane lists the tabs CMakeLists.txt (which contains the project's make code; it should be familiar if you read the commandline document) and main.cpp (which is shown and contains a trivial C++ program). These tabs appear in the order shown (but you can re-order them by draging/dropping either); if you want more control over these tabs, you can select Window | Editor Tabs | Configure Editor tabs.. (first); there you can click the Sort tabs alphabetically or Open new tabs at the end boxes (second).
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 disclosure 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 into that folder; the executable uses that folder by default for reading/writing files. Students frequently forget to put their data folders here, causing them all sorts of confusion/delay when trying to read data files.
- Depress the File tab and select Settings as shown in the following illustraton.
The following Settings window should appear on your screen.
- Disclose the Build, Execution, Deployment item, and select CMake.
The following Settings window should appear on your screen (see below for the changes needed to show this exact screen).
- Check the Automaticall reload CMake project on editing
- 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 10 below, which shows the last line).
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. These error messages 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. I recommend always doing these two operations once, for every new project.
- Click the OK button on this window.
There will be some activity briefly at the bottom of the window: CLion is and updating the cmake-build-debug folder, which may take a few minutes.
If you click (sometimes I needed to double-click) the appearing at the 2nd to bottom line of your window, the following CMake-Debug pane will appear at the bottom of CLion project window (it may appear automatically if there is a problem with your CMake file).
The CMake Debug pane will shows CLion checking whether the CMake switches you entered are legal, You can scroll through the information in the CMake Debug pane (to see if there are any errors). By clicking this same icon, the CMake Debug pane will disappear. When you scroll through the CMake Debug pane it should show something very similar to the following.
Especially important here is seeing ...cygwin64/bin/clang -- works and ...cygwin64/bin/clang++ -- works.
If you want to examine the CMakeLists.txt file, click on it (the tab 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.
- 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, which is automatically displayed. This trivialtest C++ program has now been built (compiled and linked successfully); either could have dispayed errors in the Message Build pane. Such errors must be corrected before a program can be run.
- 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 trivialtest pane; when the program terminates, the Run trivialtest pane retains the history of the program's execution (input/output).
- To edit, rebuild, and rerun the program, change the output string to 'Goodbye, World!' and then click the (Run icon) again. CLion will try to both rebuild the project and rerun it. You will briefly see the Message Build pane as shown above; because building is successful this pane will disappear the code will be run, with the Run trivialtest pane replacing it.
The following CLion project window should appear on your screen.
The results of rerunning the program appear in the Run trivialtest pane.
- 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), show a red squiggle under the error, put a purple bighlight over endl, and put a purple underline at the right end of that column, all 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.
- If we try to rebuild (or run) this code (it will fail), click the (Build icon) or (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 (there is no Run trivialtest pane because the code failed to compile/link); here you can reposition the separation between the mail.cpp and Message Build panes to show the entire program and allow all the errors to appear.
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. We assume that you have CLion open and the trivialtest project in its window.
Clion Registry Key Finder
- Create a new shortcut named ClionProjects (to the folder C:UsersyournameClionProjects, which CLion should have created, now containing only the trivialtest folder) and place it on your desktop near the shortcut that you use to start CLion.
- 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.
- 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 as shown above.
- Click the OK button on this window.
The following Open Project window should appear on your screen.
- Click the This Window button on this window. (clicking New Window creates a second project window, which is sometimes useful, but can also cause confusion; we are done with the trivialtest program in this document.)
The following CLion project window should appear on your screen (after you disclose the test_all_data_types folder).
Again, there will be some activity at the bottom (see picture below).
This happens whenever a new project is loaded. Wait for it to finish all its tasks (a few minutes at most). Also, if a message about Defender is displayed, see Section 2, Part 7 of this document for information how to proceed.
- Scroll downward, select lines 30-35, and press ctrl-/ (this notation means, while holding the Ctrl key -it is like a shift key- press the / key), which uncomments the chosen lines (recall in C++ we use // double slashes for comments).
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.
- 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 Build All pane.
- We could have bypassed the Build icon and just clicked the Run icon. In older versions of CLion, it wass useful (esepcially with programs that contain syntax errors) to Build and Run separately. If we clicked only Run, CLion would show the Message Build pane briefly; then immediately remove it -possibly losing useful information- and show the Run Build All pane. This version of CLion, seems to retain the Message Build pane, which we can access by pressing the 0: Messages button on the second to last line of the IDE.
Experiment with this driver by entering commands (and their arguments, when prompted) to better understand the set data type. You can terminate this driver either by
- entering the q command,
- clicking the (Stop icon) on the left of the Run Build All pane
After terminating the driver, click the X to the right of the Run Build All pane to close/remove it.
Note 1: if you try to close/remove the Run Build All pane before terminating the code runing in it, CLion will display the pop-up window
Note 2: so long as you don't terminate the Run Build All pane, you can redisplay it by access by pressing the 4: Run button on the second to last line of the IDE.
I suggest that you try terminating the driver with a q command; then, rerun the program and terminate it with the Stop icon. Also experiment with building/runing the code (possibly adding a syntax error by removing any of the semicolons in driver.cpp. Finally, experiment with clicking the 0: Messages, CMake and 4: Run buttons (you can try. Doing these tasks with this program now will make it easier for you to understand how to develop/debug your own code.
- We briefly examined the cmake-build-debug folder which appears in this project when test_all_date_types is disclosed.
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.
- 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 an error pop-window like
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 (unlike the CLion Run pane).appears (many different messages may appear; sometimes a sequence of error message), you likely forgot to add C:cygwin64bin to the Sytsten variable PATH (illustrated below): see the Cygwin handout, step 15, for detailed instructions on how to fix this error.
So, when a program we run under CLion terminates, its Run pane retains the input/output information (by cin/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 terminates, we can always put an input statement at the end, so it doesn't terminate until the user enters something. It is sometimes faster to run the program in an MS-DOS window, rather than in CLion.
- 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 filesloadset.txt.
- 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 its Build/Run will fail. When working on project, it is typical to
- Comment-out code in one .cpp file.
- Uncomment code in another .cpp file.
- 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, illustrated below when two main functions are uncommented.
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
- 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). All lines in driver.cpp should be commented.
- Scroll down the Project Pane (on the left) and double-click the test_set.cpp file so that it appears as an editor tab.
- Type the ctrl-a command to select all the lines in this file.
- 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 and press Enter after each entry.
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.
Is Clion Free
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. Please feel free to experiment with the CLion Integrated Development Environment and ask questions about it on Piazza. Any time that you spend experimenting with it now (before doing assignments), likely pay for itself many times over: no one wants to experiment with CLion when under deadline pressure for an assignment.