Building Complicated Software
The process of taking a bunch of files, compiling them, and then finding and attaching external libraries is called "building" software. You can think of it as being similar to taking a set of blueprints (the code) and building a finished item (the executable).
As you may have guessed, large software packages are not built by hand, since it would be far too tedious; just think about having to type a gcc command for each of the thousands of different files in a large project.
Since these are computer programmers we're talking about, the natural solution is to write a program to help us build our other programs. These tools are often called "build systems". Most IDEs (Integrated Development Environments) come with some form of a build system, and there are several standalone build systems.
The most common standalone system is called make, which is a UNIX tool that dates back to the late 1970s. Like C and UNIX, make is incredibly powerful and incredibly hard to figure out. We're not covering make at all in this course, so you don't have to worry about the details of how it works, but we are going to give you a make program (called a Makefile) that lets you build and run the programs that we'll be creating for the rest of the course. (If you're interested, feel free to take a look at what's in the Makefile; like all programs, it's just a text file.)
You do not have to use the Makefile to compile your code (and if you're using an IDE, you won't really be able to), but if you are working on ECF it will make things a bit easier for you. It will also make it a bit easier to run the tester.
make is already installed on Linux and Mac OS X, so you don't have to do anything to use the Makefile (other than downloading it) on those systems. You can install make on Windows via cygwin, but it's only worth doing that if you're already using the cygwin environment for something else.
Using the Makefile
To use the Makefile, download it and put it in the same directory as your .c files. To compile your program, type:
$ make
This runs the program make, which will look in the current directory for a file called Makefile. Assuming it finds that file, make will then execute the program stored there. Note that this program is written in the make programming language, not in C; we're using the make program to run gcc (with all of the correct flags) to compile our C program. For A3, the Makefile will compile histogram.c into histogram.o, and then compile both cardGame and letterFrequency.
To run your program, you can type:
$ make run-cardGame
or
$ make run-letterFrequency
Either of these will compile the appropriate program if necessary (i.e., make will check if the relevant .c files have changed since the program was last compiled, and compile them again if they have), and then run the program. Because make is smart enough to figure out when compiling is necessary, you can just run one of those commands every time you want to run your program, and it will figure out if you have edited the relevant files, and what (if anything) needs to be compiled.
To test your program, type:
$ make test-cardGame
or
$ make test-letterFrequency
That will compile your program if necessary, and then run the tester. Note that this will only work if you are running on ECF, since that's where the tester is installed. The other Makefile rules will work on any UNIX or UNIX-like system.
Getting the Makefile
The Makefile for A3 can be downloaded here.