I've attached a sample Makefile for Project 1. It includes targets to automatically build, test, and submit your code. Just type:
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:
This assumes you have 3 files: mycat.c, input1.txt, and input2.txt. Then you can use the makefile like this:
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.
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:
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:
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 libreadline.so in /usr/lib/ or somewhere. You can find where the .a and .so are located using the 'whereis' command:
In order to use libreadline in your code, you'll need to #include it in your source code:
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:
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.
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:
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.
1-6 of 6