Setting up CLion for CS 537

As the projects get larger and more complicated, I think it is important to have a good coding environment for this course.

I’d like to share with you how I use CLion as the main IDE for C programming. I recommend CLion for the following reasons:

  • Sync changed files to the remote server. You don’t need to manually copy and paste the modified code to the CS lab.
  • Powerful code analysis and correction suggestion. You can eliminate most of the compilation errors while you are editing the file.
  • Built-in ssh and scp support with a handy graphical interface. For Windows users, you don’t need to install PuTTY/WinSCP/WSL to connect to the CS lab.
  • Quick search and navigation. It’s much easier to search files in the project folder (compared to grep) and navigate between the declaration and definition among files (compared to vim or emacs).

Please feel free to post any questions or comments down below 🙂

Installation

You can download CLion from this link: https://www.jetbrains.com/clion/. It is commercial software, but you can get the student license for free here: https://www.jetbrains.com/student/.

The installer will ask you to configure toolchains for CLion. If you have not installed any toolchains  (gcc/llvm/MinGW/Cygwin) before, you can just skip this part, since we are probably not going to compile or run the code on our local machine.

You can follow the default configuration to finish the installation. BTW, If you are a big fan of vim, you can enable the IdeaVim plugin on the last screen.

Connect to the Remote Server

After you created your first project, go to “Tools – Deployment – Configuration”.

Click the “+” button and select “SFTP” as the type.

Under the connection tab, fill in the “Host”, “User name”, “Password” field, check the box for “Save password” (if you want to), and click “Autodetect” for “Root path”.

Under the mappings tab, choose your deployment path on the server

(I put all files under /private/CS537. You can choose whatever path you want, but don’t put it under /public)

Now the remote server is configured. You can click “Tools – Start SSH session” to connect to the CS lab via ssh

Configure File Synchronization

If you select your project folder on the left and go to “Tools – Deployment”, you can see the following menu.

You can enable the “Automatic Upload” option so that local changes will be uploaded to the server automatically.

You can also click “Browse Remote Host” to check the files on the CS lab.

For setting up the xv6 files, I suggest to copy them from /p/course/cs537-shivaram/xv6-sp19 to your private remote folder (e.g. /u/s/z/szhong/private/CS537/p1b), and then click “Download from CS Lab”.

(Note that the deployment menu is also available if you right-click a certain folder or file so that you can manually upload/download a single file/folder)

Some Useful Tips

  • Press Control (on Windows) or Command (on Mac) to jump between definition and declaration. (It’s pretty useful when navigating files in xv6)
  • Press Control + Shift + F to search among all project files
  • Double press shift to search for all file names/classes/actions…
  • Press Alt + Shift + L (on Windows) or Command + Shift + L (on Mac) to reformat code, or you can use the plugin called “Save Actions” to perform reformat on save
  • You can check the editing history under the menu “VSC – Local History – Show History”.

Has one comment to “Setting up CLion for CS 537”

You can leave a reply or Trackback this post.

  1. Xinyu - September 15, 2019 at 6:46 pm Reply

    Hi Shawn,

    I successfully setup Clion following your instruction, but there is “This file does not belong to any project target, code insight features might not work properly” on every file downloaded from CS lab and I cannot do search on them. It may be the CMakeLists issue but I do not know how to handle. Do you have any idea? Thanks.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.