UNX511/DSP912 - Lab 2: Using a Static Library

Due: Sunday, May 26, 2024

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 and its header file is pidUtil.h. 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
    $(CC) $(CFLAGS) pidUtil.cpp -o pidUtil.o

lib: pidUtil.o
    $(AR) rcs libPidUtil.a pidUtil.o

clean:
    rm -f *.o *.a

install:
    cp libPidUtil.a ../.
    cp pidUtil.h ../.

all: pidUtil lib

In a Word document, please explain every line of this Makefile.

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.