Homework 1 - Makefiles, Static and Shared Libraries


      Due: Wednesday 07/17/2002 in class

Submission:

- hand in class a printed copy of the code and the Makefile

- send by email to crisn@cs.jhu.edu, a file (hw1_name.tar.gz)containing the working directory (code and Makefile ONLY). Please make sure that you

do not include binaries or core files in the tar file.

To create a tar.gz archive, suppose the working directory is hw1_jdoe:

cd ..

tar zcvf - hw1_jdoe > hw1_jdoe.tar.gz

To extract the content of a tar.gz archive, suppose the file is hw1_jdoe.tar.gz:

tar zxvf hw1_jdoe.tar.gz



Homework:

    1) Write four routines that implement the following arithmetic operations: addition, subtraction, multiplication and division. Each function takes two integers and returns an integer. Compile it as a static library.


    2) Write a program that calls each of the four functions implemented by the above static library for numbers 8 and 4 and prints the result.


    3) Repeat 1), but this time compile it as a shared library. Implement also the _init and _fini functions (print the name of the function).


    4) Repeat 2) using the arithmetic functions from the shared library.


    5) Using compilation flags and macros, provide support for debugging. If DEBUG_MSG is defined, the four functions in the library print the input parameters and the returned result before returning. For example function int add(int a, int b) which returns a+b, will print if the library was compiled with DEBUG_MSG, a, b and a+b. Do this for both the static and the shared libraries.


    6) Write a Makefile that does all the above compilations. Make sure you use variables and implicit variables. Write also the clean target.



To see how to compile and use static and shared libraries see:

www.cnds.jhu.edu/courses/cs111

http://users.actcom.co.il/~choo/lupg/tutorials/libraries/unix-c-libraries.html