First of all, you shouldn't be compiling on the UNIX machines. You should
be compiling on the Linux machines. You should do all of your work on
p##.ecf.utoronto.ca (## is some number between 1 and 185). The machines in
your assigned lab sections are on the ugsparc network, which is different
from the ECF network. So, the first thing you should do when you log in is
open a terminal window and run:
ssh p50.ecf.utoronto.ca
(or whatever other number you prefer). When you submit your code, you must
also make sure you submit it on some p##.ecf machine, or we will never see
it.
The compiler we are using is "gcc". (This is available on both the ugsparc
and ecf networks.) The normal way(*) to compile C programs is first to
compile each .c file into an object file (.o). You do this with the "-c"
parameter like this:
gcc -c file1.c
gcc -c file2.c
gcc -c file3.c
Then link all of your object files together into an executable:
gcc file1.o file2.o file3.o -o executable
This would give you an executable called "executable". (The "-o" option
specifies the output name.)
That's a lot to type every time you want to re-compile your program. To
make things easier, you will be using makefiles for your labs. See the
lecture notes or section 5.1 of the lab 1 handout for more details about
how they work. With a makefile, you just need to type "make" to compile
your program.
Also note that we will be using one more parameter when compiling your
programs: "-Wall". (I.e. "gcc -c -Wall file1.o".) This turns on all
warnings. When you submit your code, it should compile with no errors or
warnings. An error prevents your code from compiling at all. If you have
errors you will probably get 0 for "correctness", because your code can't
even be run. If you get warnings, it means your code compiles, but there
are probably problems with it. You *will* loose marks for warnings even if
your code works correctly.
(*) It is also possible to compile your code all at once by running:
gcc -Wall file1.c file2.c file3.c -o executable
but if you're ever working on a really large project (dozens or hundreds
of files), it can take a long time to re-compile everything from scratch
every time. This is another reason Makefiles are used. With a makefile,
only the parts of your program that have been updated are re-compiled.
Your labs are small enough that this won't make a huge difference, but
it's good practice to get used to using Makefile.
Alexander Smith
Post by Jilla BejanWhat command do we use to invoke the C compiler on the unix machines ?