Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In your ubuntu, open course website (https://github.com/syracuse-fullstacksec

ID: 3810324 • Letter: 1

Question

1. In your ubuntu, open course website (https://github.com/syracuse-fullstacksecurity/cis342) (e.g. using Firefox) and hit the green "Clone or download" button to download all the files into a .zip file. Extract the zip file and cd into "marw4" directory. Type command "make" to build and execute binary "a.out". Type command "ls" to list all files. Then type command "make clean" and command "ls" to show object files (with extension ".o") are gone.

2.We use the following command to compile `h2.c` as a library: `gcc -c h2.c -o liby.a`. Edit the file named "makefile" and add a new rule about the command. You may use `compilelib` as its label. And then type "make compilelib" to compile `h2.c` as a library.

3. We can compile `h1.c` and link it to the library we just created using command `gcc -o a.out h1.c -L. -ly`. Add this command to the makefile with a new rule named `liblink`. What argument do you provide to "make" so that it can link the library liby.

Explanation / Answer

For me it didn't ask any parameter.

SRCS = h1.c h2.c
OBJS = $(SRCS:.c=.o)
OBJS = h1.o h2.o
CC = gcc

all: link
   ./a.out

link: $(OBJS)
   $(CC) $(OBJS)

compilelib:
   gcc -c h2.c -o liby.a

liblink:
   gcc -o a.out h1.c -L. -ly
clean:
   rm *.o *.out *.a

I just ran the following commands.

$make compilelib

gcc -c h2.c -o liby.a

$make liblink

gcc -o a.out h1.c -L. -ly
$ ./a.out
y=2

For simple understanding, you can re-write the makefile like below.. The following is the makefile which does the job for you. In the label "liblink" add a prerequisite. That's all. You are all done.

SRCS = h1.c h2.c
OBJS = $(SRCS:.c=.o)
OBJS = h1.o h2.o
CC = gcc

all: link
   ./a.out

link: $(OBJS)
   $(CC) $(OBJS)

compilelib:
   gcc -c h2.c -o liby.a

liblink:compilelib
   gcc -o a.out h1.c -L. -ly
clean:
   rm *.o *.out *.a

Just run "make liblink" . it will do the job for you