0% found this document useful (0 votes)
58 views5 pages

Lab 0 - (Part 2) Lab Environment Setup

Uploaded by

mir.inzamam200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views5 pages

Lab 0 - (Part 2) Lab Environment Setup

Uploaded by

mir.inzamam200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Course & Instructor Info

Course Name: CSE 4650 - Systems Programming Lab


Instructor: Imtiaj Ahmed Chowdhury, Lecturer, CSE, IUT
Lab Courtesy: CS300 - Fundamentals of Computer Systems (Brown University), adapted under CC BY
4.0

Lab 0 - Part 2
Installing Necessary Tools
In this part, you will be installing IDEs and work with Git on top of your previous setup in Part 1 of this lab.

Text Editors and IDEs


What development environment or editor to use is a question that divides people and has led to countless
hours being wasted on heated discussion, offline and online for decades. Some people prefer very simple
editors that run in their terminal, while others prefer graphical integrated development environments (IDEs).
To make your life easier, however, you probably want to use an editor with syntax highlighting for C and C++,
the main programming languages we’ll use in this lab.
You can edit your source code inside the docker lab container, or on your Ubuntu. Recall that the home
directory inside the container is a mount of your local cs300/home directory (or whatever you named it). This
means that you can install any editor or IDE of your choice on your local machine, edit your files and work on
your assignments locally, and all of your changes will be reflected in your container! You can then compile,
build, and run your assignments inside your container. This is the power of mounting 🔥!
There are plenty of great choices for text editors. For the labs, we recommend VSCode. It has very nice
integration with the Docker container, and it’s nicely customizable with extensions.

How to link VSCode with the lab Dev Environment


1. Download and Install VSCode on your Ubuntu VM (not the course container) normally
2. Navigate to the extensions tab
3. Search for and Install the “Docker”, “Dev Containers”, and “WSL” VSCode extensions via the extensions
tab
4. Make sure your course container is running (either by connecting to it, or checking the docker desktop
app)
5. Click the green button in the bottom left of VSCode, then click “Attatch to running container” and select
your CS300 course container
6. You can now open any folder you want to edit, and can get a terminal from your course container by
clicking View > Terminal

Simple editors
vim is a classic, highly configurable editor that comes with many Linux distributions. It’s a multi-
mode editor, meaning that you have to switch between modes (e.g., input, select, edit). It runs in the
terminal, all functions are controlled by keystrokes and internal commands, and vim can be customized
with plugins.
Sublime Text is a modern, lightweight, cross-platform editor highly customizable via plugins and with a
strong fulltext search.

IDEs
(Recommended) VSCode is a free IDE built by Microsoft, and has support for all major languages
(including C and C++). It also comes with built-in Git integration. Runs on macOS, Linux, and Windows,
as well as connection options to the lab Docker container.
CLion is a cross-platform IDE built by JetBrains specifically for C and C++ development. It helps you
with code navigation, generation, and refactoring. Students qualify for free licenses. Runs on macOS,
Linux, and Windows.
CLion works with CMake (an open-source system for managing the build process, comparable
to make ) to analyze and understand project context.
If you choose this option, you should import your project into CLion, so that it automatically
generates necessary CMake files for you. Please look this up for more details.
XCode is Apple’s official free IDE for Mac and iOS app development, and supports C and C++ (in
addition to various other languages). Runs on macOS.

Installing programs on Linux (in your lab container)


The provided containers come with a few programs pre-installed, but what if we want more? With a text-
based interface like the command line, it’s quite difficult to navigate the web and find a suitable download link.
Instead, we use a program called a package manager which can automatically download, install, and update
programs. We’ll be using a manager called apt . apt can install many things, including tools to build (or
compile), and debug your code. Our containers already come with these tools for your convenience.
To get practice using apt , we’re going to install some fun (and useless) command line programs, but apt is
generally the way to go for installing almost anything on your lab container.

Task

Install fortune and cowsay .


Within your container, use apt to install:

fortune - A program which outputs a random fortune when used.


cowsay - A program that generates ascii-art of a cow saying text.
You will need to use sudo , which runs commands with elevated privileges.
First, do:

1 $ sudo apt update


This builds an up-to-date index of packages available to download.
Then, for each package, do:

$ sudo apt install <package>

After installing, try it out! you can type fortune into your terminal to see a prediction for your semester, and
can use cowsay by typing cowsay "<some string>" .

cs300-user:~$ fortune
You will gain money by an illegal action.
cs300-user:~$ cowsay "What a strange fortune... At least I get some money!"
______________________________________
/ What a strange fortune... At least I \
\ get some money! /
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

Of course, apt can also be used to install more serious programs, like vim or emacs .

Extra (optional) fun

fortune generates text, and cowsay can display text in a fun way. Is there any way to combine the two? Yes!
You’ll learn about how this works under the hood later, but data can be moved from one process to another
using something called a pipe. By putting the | pipe character between two commands, the output of the first
will become the input of the second.
Try it out by running:

cs300-user:~$ fortune | cowsay

If you’re having trouble…

If you cannot run fortune or cowsay after installing them, you may need to tell the terminal where to find
these programs by adding their location to the “PATH”. You can do this by running the following command:

$ export PATH=$PATH:/usr/games

Custom packages and ./cs300-run-docker --clean

Running ./cs300-run-docker --clean will remove any custom packages that you have installed. This is
because --clean removes any existing lab containers on your system.
Fortunately, you should be able to re-install your packages with apt using your new-found package
installation skills!
If you have custom configurations for your packages, (e.g., a .vimrc file for vim ), the configurations are
persisted even if you have used --clean . This is because user-specific configurations are stored in ~ (or its
sub-directories), which are just a mount of your [DEV-ENVIRONMENT]/home directory on your machine.

Git
Git is an awesome version control tool for your code. In essence, it allows you to continuously save your
project as a sequence of small changes instead of one final thing. Some of the cool things this grants you are:

Reverting changes in case your code breaks.


Merging changes with partners, even if you’re working on the same file.
Having multiple branches, to test out implementations without ruining your code.
Retrieving stencil code and handing in solutions, like you’ll be doing throughout the semester!

There are a ton of resources out there to learn about Git, so we won’t try to recreate them. Instead, we’ll link
you to a few tutorials, and encourage you to find more on your own!
Before you start running Git commands, you’ll need to configure your name and email in Git.

Task
Within your container, set your name and email in Git.

cs300-user@9899143429a2:~$ git config --global user.name "Geralt of Rivia"


cs300-user@9899143429a2:~$ git config --global user.email "[email protected]"

If you are not already signed up to GitHub with your iut-dhaka.edu email address, add it to your profile so
that GitHub knows to correctly attribute commits to your username.

Optional: you can cache your GitHub credentials to avoid entering them in each time.

cs300-user@9899143429a2:~$ git config --global credential.helper store

Next, take a look at some beginning Git tutorials:

(Mandatory) the Harvard CS 61 Intro to Git


(Optional) Git – The Simple Guide – quick and dirty guide
(Optional) Git Handbook – in-depth introduction

GitHub Classroom Setup


GitHub Classroom is used to distribute the assignments throughout the semester. You will be working with
the lab repository which will contain a directory for each lab.

Task

Accept the GitHub Classroom assignment for the labs, then clone the repo into your container.
Labs: Set up CS300 Labs 2023

1. Enter into your container.


$ ./cs300-run-docker
cs300-user@9899143429a2:~$ # inside the container!

2. Clone the repo. Do this by going to the GitHub Repo link created by classrooms, and clicking Clone or
download. Copy the url in the box, and use it to clone like so:

$ git clone [email protected]:csci0300/cs300-s23-labs-YOURUSERNAME.git

… where YOURUSERNAME is your GitHub username. The above commands assume that you have registered an
SSH public key with GitHub; if you haven’t, try using https://github.com/cs300... instead of
the [email protected]:cs300-... URL.

Once you cloned the repository, you should see the lab directories in the labs repo.

Excercise
At this point, you have your version control set up. Let’s do a quick exercise to practice your newfound Git
skills. The results of this part of the lab are used for evaluation.

Inside the lab0 you should see a file hello_world.c . This is a Hello World program, and is the one you’ll
make changes to. To run the program you need to compile it first (we will cover compilation in detail in a later
lab). For now, just use the following commands:

$ gcc hello_world.c -o hello_world # to compile it


$ ./hello_world # to run it

Note: Make sure you do everything inside of your container.

Task
1. Modify the program so it prints the following tounge twister:
Oh, Shelley? She sells seashells by the shilling. Silly, selling Shelley.
2. Then, commit and push your changes.

You have now committed your changes to Git and they are stored in the version history ( git log should
show your new commit!). You’ve also pushed the new commit to GitHub’s servers.
So now you're all done and set for the exciting journey that awaits you in rest of the labs! Good luck!

You might also like