Lab 2 - Week 2 - Using a Static Library
Due: Sunday September 21
FIRST: See
labs.html
for information on labs.
Copy the lab 2 sample code from
https://github.com/jsellens/unx511_samples/tree/main/lab_02
(or clone/update the unx511_samples repository).
In this lab you will link a static library into your build and use the available functions inside it. The static library is
libPidUtil.a (from the unx511_samples repository)
and its header file is pidUtil.h
(also from the unx511_samples repository).
Take a look at the functions in pidUtil.h because your code will be calling these functions. You can also look inside
the contents of libPidUtil.a using nm as follows:
$ nm libPidUtil.a | grep ' T '
PART A
Your job is to create a Makefile and Lab2.cpp which links this static library in the build process and uses some of the functions inside. Lab2.cpp must:
- Call GetAllPids() and GetNameByPid() to print out all pids and their names.
- Set pid to 1. Call GetNameByPid() and print out the name of pid 1.
- Set name to "Lab2". Call GetPidByName() to get the pid of Lab2. Print "Lab2" and the pid of Lab2.
- Set name to "Lab22". Call GetPidByName() to get the pid of Lab22. There should not be a process called Lab22,
therefore this should test your error message generation system.
- If any errors are generated in the calls to these functions, the error must be printed out by a call to the
function GetErrorMsg() with the error number as an argument.
PART B
The Makefile for libPidUtil.a is as follows:
CC=g++
CFLAGS=-I
CFLAGS+=-Wall
CFLAGS+=-c
AR=ar
pidUtil: pidUtil.cpp
pidUtil.cpp -o pidUtil.o
lib: pidUtil.o
rcs libPidUtil.a pidUtil.o
clean:
rm -f *.o *.a
install:
cp libPidUtil.a ../.
cp pidUtil.h ../.
all: pidUtil lib
In a text file called
makeinfo.txt
please explain every line of this Makefile.
You could copy this Makefile, and insert comments if you wish.
Lab Submission:
Email me your Makefile and your Lab2.cpp file for PART A as well as your document for PART B to:
miguel.watler@senecapolytechnic.ca
NB: My last name is Watler, not Walter.
Lab Submission:
- Follow the instructions above
- Send email
- To: john.sellens@senecapolytechnic.ca
- Subject: lab 2 submission
- Attach your Makefile, Lab2.cpp, and
makeinfo.txt files
- Do not attempt to send a zip file - won't be accepted
- Submit lab 2 through blackboard at
https://learn.senecapolytechnic.ca/
UNX511 NSC Class Links
References
Tools
Links