UNX511
John Sellens
john.sellens@senecapolytechnic.ca
Home UNX511 Help Notes Contact

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:

  1. Call GetAllPids() and GetNameByPid() to print out all pids and their names.
  2. Set pid to 1. Call GetNameByPid() and print out the name of pid 1.
  3. Set name to "Lab2". Call GetPidByName() to get the pid of Lab2. Print "Lab2" and the pid of Lab2.
  4. 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.
  5. 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:



UNX511 NSC Class Links

References

Tools

Links





|Home|UNX511|Help Notes|Contact|


Last modified: 2025-09-11 22:53:35 -- Last formatted: 2025-09-16 13:09:00
john.sellens@senecapolytechnic.ca