Unix Systems Programming: Lab 3 - Static & Shared Libraries
Due: Friday, January 27, 2017 @ 5:00 pm
Purpose and Rationale
The purpose of this lab is to allow students to become comfortable with building Unix libraries.
Resources
FAQ
(submission instructions and other useful stuff)
Important Reminder
Lecture 3 is the primary source for this lab.
All work should be done on a machine in the department's
Linux cluster. You can refer to ssh for
more
information on
how to log into a remote machine.
Marks Distribution
Exercise 1 |
12 points |
TOTAL |
12 points |
LAB 3
EXERCISE 1: Build Static and Shared Libraries using a
Makefile
- Read chapters 41 and 42 of Kerrisk, with special focus on chapter 41.
-
Read "The make Command and Makefiles" session in Chaper 9 of BLP
textbook
if you're using that text. Certainly refer to the online GNU
documentation
for GNU
make.
- Write 3 very simple c source files: hello.c,
here.c, bye.c, mylib.h
. In hello.c, a function should print out
"Hello!"; in here.c
, another function should print out "I am here!"; and yet another
function
should print out "Bye bye!" in bye.c. So,
actually, in each code
file, there is only one C printf statement. mylib.h should include
prototypes for the 3 functions you will be writing.
- Write a main.c to call above 3
functions so that the result should display like following
"Hello!"
"I am here!"
"Bye bye!"
Please note there is no C printf statement in main.c;
- Read and understand this
makefile first and write your own Makefile called Makefile1
to compile them and build a static lib called mylib.a,
comprised
of hello.c, here.c, and bye.c (but NOT main.c).
Review "shared libraries naming structure" and
"building a shared library" in lecture 3.
- Read and understand this makefile
first and write your own makefile called Makefile2
to compile them and build a shared lib with the soname of
libmylib.so.5. Make the minor
version .1 and the release .10. This will mean your actual
shared library
file will be named "libmylib.so.5.1.10" with .so links set accordingly.
Note that the two makefiles actually build separate
libraries based
on the same source code files, one static, the other shared.
DELIVERABLES: your source file(s)
(e.g., main.c, hello.c, bye.c, here.c, mylib.h), two makefiles, and a README as
described below in Deliverables
Carefully follow the steps below.
- Please create a subdirectory ex, and include eight files
- Five source code files : main.c, hello.c, bye.c, here.c, mylib.h
- Two Make files, which will build an executable called : main
Makefile1 : for building static library
Makefile2 : for building shared library
- One README file: it will contain two lines, the exact command line argument to build an executable called main
make -f Makefile1 target
make -f Makefile2 target
- When you are finished with your directory you will create a
compressed archive file using tar
(this utility stores your directory as a single file, then compresses
its size.)
tar -czvf username.lab3.tgz username.lab3
- You will email your file to our TA as an attachment. He will send an acknowledgement that your assignment has been
received.
To |
Nicholas Flees
(nickflees@uchicago.edu) |
Attachment |
username.lab3.tgz |
Subject |
CSPP51081-lab3 |