Welcome to CS 3410! In this course we will learn about computer systems organization and programming. Most systems programming is done in the C programming language, or in a similar language. Today you will compile a simple C program. Also, you will install a virtual machine for the course that can run on your local personal computer. If you do not have a personal computer, then you can use the departments CS undergrad lab (CSUG) computers. Simply follow the instructions below.
If you are working on your own computer, you will need to download and set up the CSUG lab virtual machine in order to have access to a copy of the lab's Linux environment. First you have to obtain the disk image as follows:
\\en-csuglab.files.cornell.edu\en-csuglab\courses\vm
and copy the file en-cs-uglab-vm-x11-20140206.7z
onto your local computer. csug01.csuglab.cornell.edu
or csug02.csuglab.cornell.edu
or ... or csug03.csuglab.cornell.edu
. Log in with your NetID and password. Then go to the directory /courses/vm
and copy en-cs-uglab-vm-x11-20140206.7z
over to your computer.smb://en-csuglab.files.cornell.edu/en-csuglab/courses/vm
and click Connect. Then copy en-cs-uglab-vm-x11-20140206.7z
over to your computer.scp [netid]@csug14.csuglab.cornell.edu:/courses/vm/en-cs-uglab-vm-x11-20140206.7z ~/Desktop
" where you replace [netid]
with your NetID. If asked a yes/no question, type in yes
. You will be asked for your NetID password. After that, scp
will copy the virtual machine disk image to your Desktop.
scp [netid]@csug14.csuglab.cornell.edu:/courses/vm/en-cs-uglab-vm-x11-20140206.7z ~/Desktop
" where you replace [netid]
with your NetID. If asked a yes/no question, type in yes
. You will be asked for your NetID password. After that, scp
will copy the virtual machine disk image to your Desktop.
If you do not have a personal computer or you were not able to install successfully a virtual machine, you may log into a CSUG computer and complete the rest of the lab there.
For Linux and Mac users, simply typet the command:
ssh [netid]@csugXX.csuglab.cornell.edu
(Replace XX
with a number between 01-14 and [netid]
with your NetID.)
For Windows users, download an SSH client. The recommended SSH client is PuTTY. To connect to CSUG machines using PuTTY:
1.) Open PuTTY
2.) Under Host Name enter: [netid]@csugXX.csuglab.cornell.edu
(Replace XX
with a number between 01-14 and [netid]
with your NetID.)
3.) Press Open
4.) A window labeled 'PuTTY Security Alert' should pop-up which provides a warning about the host key. Click Yes.
5.) You are connected.
Now that you are in the virtual machine or on the CSUG computer, you should be able to write, compile, and run simple C programs. Run the command:
nano hello.c
This is a simple text editor, and we will use it to write a C program. Carefully type in the following C program:
#include <stdio.h>
void main() {
printf("Hello world! I am [netid].\n");
}
But replace [netid]
with your NetID. When you are done typing, press Ctrl+X followed by Y to save and exit, and hit the Enter or Return key a few times until you are again at the command prompt. Now you are ready to compile and run the program you just created! Run the command:
gcc -o sayhello hello.c
If this gives you any errors, go back to nano hello.c
and fix the program. Otherwise, you have just compiled a C program. You can run your program by running the command:
./sayhello
And your program should run! It should print "Hello world! I am [netid]." and do nothing else.
What does ./sayhello
mean? The C compiler (GCC) has compiled your source code hello.c
into a program sayhello
. The command ./sayhello
means, "Run the program sayhello
in the current directory."
hello.c
and sayhello
files to CMSNow you must upload the hello.c
and sayhello
files to CMS. To do this, you must first get those files out of the virtual machine. The easiest way to do this is by sending yourself an email with the two files as attachments. To do this, run the command:
echo "Sending files." | mail -s CLab0 -a hello.c -a sayhello [netid]@cornell.edu
But replace [netid]
with your NetID. Run this command. If succesful, this command will say nothing. In a few minutes you should receive the files for CLab0 in your cornell.edu mail account. Make sure to check your spam folder.
Upload both files to CMS, and pat yourself on the back. You are now officially a C programmer!
Section 1.3 of the assigned book "C: A Refernce Manual" is a good overview of C programming, and it includes a "Hello World" example like this lab.
There other ways to transfer files out of the virtual machine. Please look at these slides for more information on VMs and Unix, including some alternative ways of transferring out your files.