New Makefile

I've attached a sample Makefile for Project 1.  It includes targets to automatically build, test, and submit your code.  Just type: $ make submit

Feel free to use the Makefile for your future projects; just update it accordingly.


Before submitting code for your projects, you must create a Makefile.  You need at least one target, 'test', which will run your program with your own sample input.

Makefiles must be named "Makefile" or "makefile".  Below is a sample Makefile for project1:

mycat: mycat.o

mycat.o: mycat.c

    rm -f *.o

test: mycat
    ./mycat input1.txt input2.txt
    ./mycat --rot13 input2.txt
    ./mycat --help

This assumes you have 3 files: mycat.c, input1.txt, and input2.txt.  Then you can use the makefile like this:

$ make mycat
$ make test

The 'mycat' target builds your program using your default C compiler (cc).  The 'test' target runs your program a few times to show that it works.

Please note: it is your responsibility to write your makefile such that it demonstrates all required functionality for a given project.  For example, project 1 requires the -h flag to work.  You should modify the Makefile to show that it works too.

Submission Procedure

The Makefile attached below includes a "submit" target which uploads your project to my submission server.  You can modify it to fit your needs for each project.

Alternatively, you can submit your code using the shell script attached below.  You can download the script from a terminal like this:

On Mac OS X you can try:

$ curl -L --output

  1. Put all your source code, input files, and Makefile in one folder
  2. Create a tarball like this: $ tar -czvf project1.tar.gz myfolder
  3. Make sure you name your tarball something descriptive, like project1.tar.gz
  4. Set an environment variable 'PAWPRINT' with your MU pawprint.  This works if your shell is bash: $ export PAWPRINT=<yourpawprint>
  5. Run the submission script, specifying your tarball as argument: $ sh ./ project1.tar.gz
  6. The submission system will build and test your tarball locally before uploading the results.  Verify that your program ran correctly.
  7. If everything goes well, the submission system will provide you with a link.  Verify that the link works by pasting it into a browser or something.  The link should be kept secret.
  8. If you need to, you can re-submit multiple times.  The system will overwrite any previous submissions made from your computer, so make sure your last submission is the one you want graded!

Using External Libraries

In order to link to libraries in C, you need more than just a header file.  You also need one of the following:

  • the source files (.c) that implement the library, e.g. if you are writing the library as part of your project
  • compiled object files (.o) of the source files, e.g. if you already compiled them yourself
  • compiled libraries (.a) combining several object files
  • a shared-object stub (.a) which links with a shared object file (.so, analogous to a .dll in Windows)
On modern operating systems, it is usually very easy to install .so and .a files.  On Ubuntu/Debian, for example, you can install libreadline and libhistory like this:

$ apt-get install libreadline6 libreadline6-dev

The libreadline6 package includes all the .so files used by pre-compiled programs that use libreadline/history.  The libreadline6-dev package includes the .a files required to link your own programs with libreadline/history.

Most operating systems will have libreadline/history installed by default.  Once installed, you should see libreadline.a and in /usr/lib/ or somewhere.  You can find where the .a and .so are located using the 'whereis' command:

$ whereis libreadline
libreadline: /usr/lib/libreadline.a /usr/lib/ /usr/lib64/libreadline.a /usr/lib64/

In order to use libreadline in your code, you'll need to #include it in your source code:

#include <readline/readline.h>
#include <readline/history.h>
#include <stdio.h>
#include <stdlib.h>
int main () {

The paths <readline/readline.h> etc may be different on your operating system.

A #include tells the compiler (cc) to include the header files in your source.  However, header files are just declarations, not definitions.  In other words, the compiler will know that readline() and add_history() are valid functions, but it will not know what they do!  If you try to compile your program like this, you will get "undefined reference to readline/add_history" errors.  This is because you have not linked your program to libreadline yet!

To link your code to a library (.a file), use the '-l' linker option:

$(CC) -lreadline -lhistory -o myshell myshell.o

The -lreadline option tells the linker to link your .o files with libreadline.a.  As you will see next, you can do this really easily in your Makefiles.

Note for Mac users: on Mac, libhistory and libreadline are compiled together into one library, so you only need -lreadline.

Advanced Makefiles

I encourage you to make your Makefiles as simple as possible.  Make is smart enough to figure out how to build your project with just a little help.  Here is an example Makefile that will compile mysh.c and link with libreadline/history automatically:

# set up linker options
LDLIBS= -lreadline -lhistory

# set up compiler options (-g means include debug info)


     rm -f *.o mycat mysh

test: all
    ./mycat file.txt
    ./mush script.mysh

Notice that you can specify all your libraries in one line using the LDLIBS flag.  Make will use this flag whenever it runs the linker.

Project 6 assigned

posted Mar 15, 2013, 6:53 AM by Ryanne Dolan

Project 6 is due at the end of the semester.

Project 5 assigned

posted Mar 5, 2013, 11:11 PM by Ryanne Dolan

Project 5 is due upon return from Spring Break.

Project 4 assigned

posted Feb 14, 2013, 8:51 AM by Ryanne Dolan

Shell 3 is due 3.1

Project 3 assigned

posted Feb 14, 2013, 8:49 AM by Ryanne Dolan

Shell 2 is due 2.22

Project 2 assigned

posted Jan 24, 2012, 11:45 AM by Ryanne Dolan   [ updated Jan 29, 2013, 10:04 PM ]

Shell 1 is due 2.8.13.

Project 1 assigned

posted Jan 17, 2011, 11:35 PM by Ryanne Dolan   [ updated Jan 29, 2013, 10:03 PM ]

Project 1 is due 2.1.13

1-6 of 6

Ryanne Dolan,
Jan 30, 2012, 6:51 PM
Ryanne Dolan,
Feb 17, 2011, 11:02 PM