tutorial 4: 'C' programming on Linux

Getting started

Write, compile and execute a hello world! program if you have not already done this.

Copy the example programs in the lecture notes, study the source code and compile and run these program.

gcc compilation options

Develop a program involving more than one source file. Compile the object files seperately using gcc. Then link these into an executable file. Run this program.

using a make file

Create a make file to handle the compilation of your program. Ensure that only the object file which is out of date is updated if one of the source files is changed. You can tell which files are changed by using a ls -l listing of your source directory and comparing modification dates and times.

Extend your makefile to enable a different target (e.g. debug) which compiles your program with the option to allow for debugging using gdb.

using gdb

Run your program in gdb. Create a break point and output the value of program variables. Step through execution after the break point examining changes to these variables.