CS 70

Setting Up a C++ Development Environment

In this part of the assignment, you'll set up your own computer to be able to compile and run C++ code! There are two critical pieces of software we'll need: a C++ compiler (which you read about in this week's lessons), and Git (which we need since we'll be fetching HW1 starter code from GitHub). Once you've installed the necessary software, you'll test it out by trying to compile to HW1 starter code.

Installing Our Toolchain

The exact process of installing the necessary software varies depending on your operating system. Therefore, to proceed, please select your operating system below:

  • LHS Cow speaking

    BOTH partners should do this on their own computers!

Cloning the HW1 Starter Code

In future assignments, you'll be using VS Code's built-in Git integration to clone the starter code (like described in HW0). But in the "looking under the hood" spirit of HW1, in this assignment you'll instead run the Git commands manually. To do so, follow these steps:

  • RHS Cow speaking

    Once again, both partners should follow these steps on their own computers!

1. Open a terminal inside VS Code

To get started, open VS Code, but make sure that you do not connect the VS Code window to the CS 70 server. To verify, the bottom left corner of VS Code should show only the >< and should not say connected to cs70.cs.hmc.edu or anything like that. Then, open the VS Code built-in terminal, either by using the menu View > Terminal or the keyboard shortcut Ctrl+` (Cmd+` on Mac).

2. Choose where on your computer you want the code to go

By default, the VS Code built-in terminal will start inside your "home folder". That's the "default" folder that contains other folders like Documents, Downloads, Music, etc. On Mac OS, this folder is /Users/<username>. On Linux, it's /home/<username>. And on Windows, it's C:\Users\<username>.

Any commands you run in the terminal at this point will happen inside this folder. Therefore, if you were to go directly to Step 3 at this point, the cloned repository would end up in /Users/<username>/<repository name> (or the equivalent Linux or Windows directories). If you're okay with that, then you don't need to do anything else here, you can move on to Step 3. But if you want the code to go in a different folder, you'll need to navigate the terminal to that folder. This can be done using the cd command. For example, if you like to organize all your homework inside your Documents folder, you can run cd Documents to navigate the terminal from its current location (the home folder) to the Documents folder.

  • Rabbit speaking

    The way to remember cd is that it's short for "change directory" (where "directory" is a technical term for "folder")!

It's up to you where you want to put your code, but make sure you remember where you put it!

3. Clone the repository

To clone your HW1 repository, you first need to copy the repository's URL, following the same steps as in HW0. Then, in the terminal, run the following:

git clone <url>

Where <url> is the URL you copied.

If you previously did HW0 on this same laptop, VS Code should remember your GitHub login info and the command should just work. Otherwise, it may ask you to sign in again.

  • LHS Cow speaking

    Let course staff know if you run into any problems with authentication!

The above command is (more or less) what VS Code is actually doing behind the scenes when you press the "clone repository" button! Therefore, just like if you had used that button, you should now end up with a local copy of the HW1 starter code. This local copy will be saved in the folder you chose in Step 2. Specifically, inside that folder, you should now find a new folder with the same name as your GitHub repository. For example, if you chose the Documents folder in Step 2, and your GitHub repo is named hw1-jonathan-melissa, the downloaded HW1 code will be in /Users/<username>/Documents/hw1-jonathan/melissa.

4. Open the HW1 starter code in VS Code

If you had cloned the repository code using VS Code's built-in git integration, it would have offered to open the downloaded code automatically, like in HW0. But because we cloned it manually, we will need to open the code manually as well.

In the same VS Code window, go to File > Open Folder.... Because you are working on your own computer and not the CS 70 server, this will bring up a normal file picker. In the file picker, you should havigate to the folder you chose in Step 2, and inside there you should see another folder with the same name as your GitHub repository (as described in Step 3). Select this folder to open in VS Code, and all your code should show up!

5. Take a picture!

To prove that you got things working, one partner should take a screenshot of their VS Code window with the file fontfun.cpp (located in the fontfun folder) open. Make sure the screenshot includes the lower left corner of the VS Code window, showing it is not connected to the server! Save the screenshot inside your HW1 folder as <partner's first name>.jpg.

Now you're going to add this file to be tracked by Git, and commit and push it to GitHub. Once again, we will do this manually. In the terminal window, use cd to get inside the HW1 folder. Then run:

git add <partner's first name>.jpg
git commit -m "Adding first partner's screenshot"
git push

To explain what this command is doing:

  • The first line tells Git to track the new screenshot file
  • The second line commits this change in the local repository
  • The third line pushes this commit to the remote repository

Once again, the VS Code built-in Git integration is actually running all three steps behind the scenes for you when you use it to push commits. Isn't it neat to see what's going on behind the scenes?

Finally, the other partner should pull the changes by running:

git pull

Then they should repeat all the above steps to add their own screenshot to the GitHub repository.

To Complete This Part of the Assignment…

You'll know you're done with this part of the assignment when you've done all of the following:

(When logged in, completion status appears here.)