Before we can get started we need to install our development environment. You’ll need a C++ compiler, the CLion IDE, and Git for version control. You should be able to start on to the next section, GitHub Setup, while files are downloading.
OS X automatically installs its toolchain, including Git, when you
attempt to use it from the command line for the first time. Thus, to
install developer tools, run the Terminal program (from
Applications/Utilities
) to get a command prompt. At the prompt, type
clang
and press return. A dialog box will pop up and offer to install the command-line developer tools for you. Say yes.
(Alternatively, you can install the latest version of Command Line Tools for OS X manually from Apple, or install XCode from the App Store.)
On Windows, you need to install MinGW (the C++ compiler) and Git separately:
-
MinGW
- Download and run the installer from mingw.org.
- Follow the prompts to install MinGW.
- At the end, hit “Continue“ and the MinGW Installation Manager will open.
- Select the “mingw32-base” and “mingw32-gcc-g++” packages by “marking for installation” using the check box.
- Click the “Installation” menu to the top left corner and select “Apply Changes.”
- Click “Apply” in the window that pops up.
- You can quit after “All changes were applied successfully” appears.
-
Git
- Download and run the installer from git-scm.com.
- Click “Next” for each question until “Adjusting your PATH environment” appears. Select “Use Git from the Windows Command Prompt” instead of the default option. Then continue clicking “Next” until the installation completes.
Make sure you have Git and a working C++14 toolchain installed.
-
Register for a student account at www.jetbrains.com/shop/eform/students
-
Follow the instructions in your email to activate your account.
-
Download CLion from jetbrains.com
-
Run the installer—defaults should be fine. (Windows: check all of the “Create associations” boxes when they appear.)
Git is a source control tool that you’ll be learning more about later in this lab. In short, it keeps track of each version of your files, so that you can:
-
Go back to any previous version. This is useful because it means that mistakes are easy to undo, and it’s safe to experiment.
-
Have multiple versions (branches) simultaneously. You may use separate branches for different features you are developing or ideas you are trying, so that you can switch between them without them interfering with one another. This also allows multiple developers to work on the same project concurrently without stepping on each other’s toes.
-
Copy changes from one version to another. For example, if you are happy with a feature that you developed in a feature branch, then you can copy the changes into the main (master) branch.
GitHub is a service that hosts Git repositories (where all the versions are stored) online to facilitate collaboration. In particular, you will (probably) use GitHub when handing in your homework. Thus, you will need a GitHub account, and we will need to know your username:
-
If you don’t already have a GitHub account, go to github.com and sign up for one.
-
Let us know your GitHub username by registering it here.
Once we have everything set up, the main task for this lab is to make sure everything works. The code for this lab is a CLion project hosted on GitHub. In this section, you will make your own copy (fork) of the project on GitHub, make a local copy to work on using CLion, make a small change, and then push your changes back to GitHub.
-
Go to the lab repo page and click “Fork” in the upper right. (If it asks where to fork it, choose your GitHub account.) This will make a copy of the lab1 project in your own GitHub account. You can see my forked copy at https://github.com/tov/lab1. Yours should look similar, but with your username in place of “tov”.
-
Above the file listing table, you should see a row of buttons starting with “Branch: master” and “New pull request”. Further to the right, you should see a drop-down menu button labeled either “HTTPS” or “SSH”—if “SSH” then change it to “HTTPS”. The text in the box to the right of this is your repository URL, which identifies where to locate your code when using other programs, such as CLion. Copy your repository URL to the clipboard. Mine is
https://github.com/tov/lab1.git
, and yours should be similar. -
Now that you have a URL for your own lab1 repository, you will clone it in CLion, which makes a local copy that you can work with. If you are on the initial CLion screen, which presents recently opened files and four main options, choose the last option, “Check out from Version Control”. (If you have a project open already then you’ll find this option on the “VCS” menu.) Choose Git, not GitHub, as the kind of repository. Paste your repo URL where it asks for the “Git Repository URL”. The other options let you choose where to put your local copy of the project; change them if you like, and click “Clone”. This should create a new CLion project, which you can open.
-
You should now be able to build and run the lab1 project. Choose “Run 'Build-All'”, “Run 'lab1'”, or something like that from the “Run” menu. The program should compile and run, printing the message
Hello, world!
-
Now we are going to make a small change to the program. (It’s okay if you don’t understand what we’re doing here yet—I don’t expect you to.) The lab1 project should contain a subdirectory
src
, which contains a C++ source filelab1.cpp
. Using the project browser on the left, navigate to this file and open it. The entire text of the file should read:#include "eecs230.h" string name = "world"; int main() { cout << "Hello, " << name << "!\n"; }
Instead of greeting the world, modify the program to greet you. You can do this by changing
"world"
to something else. For example, I would change it to:string name = "Jesse";
Run the program again and make sure your change worked.
-
There are two steps involved in saving your changes using Git. The first step is to commit your changes to the local repository, which makes a new version locally. Then you need to push your changes to the remote repository (GitHub). To do the former, select “Commit Changes...” from the VCS menu. It will give you a chance to review the changes and write a descriptive comment about the change before committing. Then push to GitHub using the “Push...” command from the “Git” submenu of the “VCS” menu.
-
Now your changes should be visible in your forked repository on GitHub. Go back to your repo page, navigate to
src/lab1.cpp
, and confirm that your name has replaced"world"
.
If you have time remaining, start this interactive git branching tutorial. If you run out of time, it would still be valuable to do it at home.