For Homework 0, we set up the accounts and tools needed for this course.
Overview
- Set up our VPN. We need access to services that require we are within UCI's network. When we are on campus, we do nto need to use the VPN, but whenever we try to access these services off campus, we will be required to use it.
- Activate our ICS Account. This is NOT the same as our UCI NetID. We need this account to access the ICS 46 Hub.
- Login to the ICS 46 Hub, where we develop all our programs. Hub provides an online editor with tools such as Visual Studio.
- Set up
git
. - Complete a basic C++ program, to verify that our environment is correctly set up.
- Compile with
g++
and run. - Learn to use
valgrind
. - Create a
Makefile
to compile. - Push changes to git.
- Submit to GradeScope
Go to UCI VPN and download the corrosponding client for your operating system.
- Following all the directions should have you complete the download and connect to UCI.
Create your ICS Account using this link: ICS Account Creation Website.
- You need to be on campus or use the VPN.
Login to the course Hub using this link: ICS 46 Hub
- You need to be on campus or use the VPN.
- You need to log in with your ICS Account.
- When logging in, use just the username, not the full email (use
example
NOT[email protected]
)
- Sign in to the Hub
- You will be greeted with this homepage
GitHub is an online storage service for the tool git
, an industry standard version control tool with many powerful capabilities. For this course, git
allows you to
- easily obtain files needed for each Homework from the ICS46 course repository,
- save your work in your own account on GitHub (in different versions/branches if you choose, so that you can try different approaches or changes without breaking what you were working on before), and
- easily upload your Homework submissions to GradeScope directly from GitHub.
This class requires the use of a GitHub account, so first create your account at GitHub.com. If you already have a GitHub account, you can use your existing account for this course. Your GitHub account does not need to be linked to your UCI email.
git
is pre-installed, so now we will set up your basic git
profile and add your GitHub ssh-keys
to your account! SSH keys allow secure communication between your Hub and your GitHub accounts, without the need to log in every time.
Once logged in to the Hub, click the Terminal
button, which should be the first link in the Other section. In Terminal, you can now type commands to git
.
When using a terminal, always be aware of your current working directory, and whether your current directory is your local machine (i.e., on the hard drive of your own computer) or remote, on Hub. When following these instructions, make sure you are logged into Hub!
In your Hub terminal, add your GitHub username
and email
by typing the following commands. The commands below shown as <Example>
should be replaced with your information:
git config --global user.name "<YourGitHubNameHere>" # Example: "Ray Klefstad"
git config --global user.email "<YourGitHubEmailHere>" # Example: "[email protected]"
Now set up an ssh
key, because GitHub
is moving away from allowing https
links.
First, generate an SSH key pair for GitHub on Hub through the following steps:
- Type or copy the following command, using your GitHub email:
ssh-keygen -t ed25519 -C "<YourGitHubEmailHere>"
When you're prompted to Enter a file in which to save the key
, press Enter
to accept the default file location.
- At the next prompt, you can enter a passphrase to protect your SSH key, or simply hit
Enter
(twice) for no passphrase.
$ Enter passphrase (empty for no passphrase): [Type a passphrase]
$ Enter same passphrase again: [Type passphrase again]
Now that you have created your SSH key on Hub, add it to your GitHub
account as follows:
- Copy the SSH public key to your clipboard:
Then select and copy the contents of the
cat ~/.ssh/id_ed25519.pub
id_ed25519.pub
file displayed in the terminal to your clipboard. which should look like this:ssh-ed25519 <content> <email>
- On your account at GitHub.com, in the upper-right corner of any page, click your profile photo, then click Settings.
- In the left sidebar menu, click SSH and GPG keys.
- Click New SSH key or Add SSH key.
- In the Title field, add the informative label
Hub
. - For the type of key, make sure Authentication is selected.
- In the Key field, paste your public key.
- Click Add SSH key.
Now that you have set up your username
, email
, and ssh
key, navigate back to the Canvas page, and click the GitHub Classroom link. That link will automatically generate a private copy of this repository for you! (NOTE: It will ask you to authorize GitHub Classroom to have access to your GitHub account, and you should confirm this authorization). Once you have created that repository, you can continue on to the Clone
instructions in Step 4. Go to the browser tab with your private ics-46-hw0-<yourgithubid>
repository to continue with the instructions.
Now that you have a private copy of this repository, clone your private GitHub Classroom
ICS46 (ics-46-hw0-<yourgithubid>
) repository to your Hub. On Hub, you can clone a GitHub repository by using the command git clone
and copy-pasting the SSH link you get when clicking the green Code
button. Example below:
First lets create a new folder to store all of our repos:
Create a folder named ICS46
Double click it to go inside the folder Click the Terminal link, which is the first button under the Other section.
Now run the following command:
# This is an example ssh link, make sure to use your own!
# NOTE: the `HW0` following the .git address indicates what folder to
# name the project you are cloning.
git clone [email protected]:klefstad-teaching/ics-46-hw0-<GitHubUserName>.git HW0
At the prompt Are you sure you want to continue connecting (yes/no/[fingerprint])?
type yes
.
This git clone ...
command initializes a new git repository on your Hub and populates it with the contents of the private HW0
repository from GitHub Classroom, adding the directory HW0
to your current working directory, which you can see by typing the ls
command.
The git clone
command also establishes the private course repository at HW0
as a remote
connection called origin
. origin
is an alias (short nickname) for [email protected]:klefstad-teaching/ics-46-hw0-<GitHubUserName>.git
so that you don't have to type that long connection path every time. You can then checkout
files from origin
for all the future Homeworks (from the different branches named hw0
, hw1
...)---but only after they are announced as available on Ed!
-
Exit out of the terminal and click the VS Code link, the last link in the 'Notebook' section
-
Click the menu button in the top left and go to
File > Open Folder...
and type in the path for ourHW0
folder:/home/<username>/ICS46/HW0
.
- Create a new file called
main.cpp
and type up the "Hello World" program shown below.
-
Click the menu button in the top right and go to
Terminal > New Terminal
. -
Compile the program with the following command. This most basic g++ command, without any other options, compiles main.cpp, links it with any library files, and creates an executable called a.out.
g++ ./main.cpp
- Give the command ls to see the file a.out that was created by the compiler.
ls
- Run the program by typing a.out
./a.out
- Valgrind is a valuable tool for detecting runtime errors in your C++ program. For basic checking, use the following command:
valgrind program_name program_arguments
- Or for careful checking, the following command and arguments
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --track-origins=yes program_name program_arguments
⚠️ Note: You must run valgrind on your program for several Homework assignments to come.
- Now run valgrind to check for memory leaks and other memory access errors. Below is a simple command and a complex command to run valgrind. Try the simple one first, then the complex one.
valgrind ./a.out
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --track-origins=yes ./a.out
- Remove the a.out file with the rm command, then list the contents of the current working directory with ls to verify that it is gone:
rm ./a.out
ls
⚠️ Note: Be VERY careful with the rm command. The default permanently deletes without confirming.
- Now create a Makefile for your program so that you can automatically recompile your program using lots of options with the simple command make, instead of having to type all the options repeatedly. Create a file named Makefile (the M must be capitalized!) in the same directory as your program. In line 3 of the screenshot below, the indentation before g++ must be one <tab> character.
⚠️ Note: If you use spaces, it will not work! Also note that in the monospace code font below, 0 (zero) has a dot or line in the middle, while the uppercase letter O and lowercase o do not.
- An alternative to the tab character is to use a semicolon after main.cpp, followed by g++ all on the same line, like this:
main: main.cpp ; g++ $(CXXFLAGS) main.cpp -o main
- Give the command make to build your program (it should execute the g++ command to build main)
make
- Now run your program called main
./main
- Add a new rule to your Makefile for clean to remove the files you no longer need. Add lines 4 and 5 to the bottom of your Makefile (again, the indentation must be done with one character):
- Type make clean to remove the executable:
make clean
- Type ls to verify that main is gone.
ls
- Now type make again with your changed Makefile to compile and build a new executable. The new Makefile should give all those options to the compile command. You may see more error messages now. Never ignore warnings! Fix each one.
IMPORTANT
For all the GTests to work and for the autograder to work as intended you must add a src
directory and move the main.cpp
file into it
└── src
├── main.cpp
- Create a
src
folder in your root directory - Move your
main.cpp
file into the newly createdsrc
folder - Click the third button underneath the menu button on the top left named Source Control
- Press the blue
Commit
button, and clickYes
on the alert that pops up saying:
There are no staged changes to commit.
Would you like to stage all your changes and commit them directly?
- A file will pop up asking to give a commit message, type one out after the lines that start with the
#
character - Once you have entered a commit message, press the check mark button on the top right or close the file.
⚠️ Note: If you do not type out a commit message, or if you put it on a line starting with the#
character it will not work, and the blueCommit
button will remain the same.
- Press the blue
Sync Changes
button and clickOk
on the alert that pops up saying:
This action will pull and push commits from and to "origin/main".
All submissions are done on GradeScope.
On GradeScope, go into your Account Settings, and link your GitHub account to GradeScope.
Then on the course GradeScope, go to the Homework 0 assignment, press the Submit button, choose the GitHub option, and select your project and branch.