This tutorial will introduce you to the process of creating and submitting laboratory exercises in CMSC 123. In every exercise, you will be handed a tar file that contains a set of files that will serve as your starting point. Let's get started..
$tar xzvf 123sample.tar.gz
You'll get following files inside the sample folder: Makefile, max.h, max_test.c,main.c,README
$cd sample
$make
make: *** No rule to make target `max.c', needed by `max.o'. Stop.
The error above will be displayed, which simply means that max.c is needed to build the program but it was not found.
$touch max.c; make
gcc -c max.c gcc -c max_test.c max.o -lcunit gcc: max.o: linker input file unused because linking not done gcc: -lcunit: linker input file unused because linking not done gcc -o max_test.exe max_test.o max.o -lcunit max_test.o(.text+0x24): In function `test_maxi': : undefined reference to `maxi' max_test.o(.text+0x5d): In function `test_maxi': : undefined reference to `maxi' max_test.o(.text+0x95): In function `test_maxi': : undefined reference to `maxi' collect2: ld returned 1 exit status make: *** [max_test.exe] Error 1
The above error will be displayed which indicates that there is an undefined reference to a function maxi which is true because we have not defined a function named maxi yet.
#include#ifndef __MAX_H__ #define __MAX_H__ int maxi(int i1, int i2); #endif
#include <stdio.h>
#include "max.h"
/**
* Returns the maximum of two numbers
*
* @param i1 the first number
* @param i2 the second number
* @return the maximum of i1 and i2
*
*/
int maxi(int i1, int i2){
int retval=0;
if (i1 > i2){
retval = i1;
}else{
retval = i2;
}
return retval;
}
$make
CUnit - A Unit testing framework for C - Version 2.1-0
http://cunit.sourceforge.net/
Suite: Suite_1
Test: Test of maxi() ... passed
--Run Summary: Type Total Ran Passed Failed
suites 1 1 n/a 0
tests 1 1 1 0
asserts 3 3 3 0
The result above shows that all the test passed which means that we have properly defined the function maxi. If you want to see how maxi was tested, look inside max_test.c. CUnit is used as the unit testing framework.
INITIALS=jach
$make clean;make submit
A file named jach-sample.tar.gz will be created in the directory above sample. This tar file is what you are going to submit to your instructor.
To do your exercises in the class, the following steps will be followed.