Lab Exam : Makefile Review Flashcards

1
Q

How do you make gcc not link what it makes?

A

Use the -c option.
When -c is omitted, it looks for a main function for the entry point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What recipe compiles an object file?

A

module1.o: module1.c
$(CC) -c $(CFLAGS) module1.c -o module1.o

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What recipe links the files?

A

my_prog: module1.o module2.o
$(CC) $(CFLAGS) module1.o module2.o my_prog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

CFLAGS

A

-Wall -Wextra -pedantic -std=c99 -g

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

CC

A

gcc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What do header files contain?

A

.h files contain function prototypes (or “headers”), type definitions, and useful macros.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What files need to include header files?

A

Files that implement the functions listed or use the functions listed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

-I (captial i) option

A

Adds a place to search to the preprocessor’s list. This gives the preprocessor an additional place to search.
I.e. -I. for the current directory
Note that there can be many -I flags

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do you store -I (capital I) in?

A

CPPFLAGS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you write a header file?

A

ifndef FILENAME_H

#define FILENAME_H
//stuff goes here
#endif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you link files together into a static library?

A

ar rcs libname.a module1.o module2.o ….

This creates a library called libname.a which contains the object files.
Note that they MUST begin with “lib” and end with “.a”.
(or “.so” for dynamic libraries).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you link a library during the linking step?

A

use -L and -l (lowercase L) options when invoking gcc.
-L followed by the directory (i.e. -L/home/…) says where to look for library files.
-l followed by the name of a library tells gcc to link a specific library from one of the locations given by -L.
I.e.
-lname-name tells gcc to find libname-name.a
Use LDFLAGS for these.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Where do you put the -L flags?

A

In LDFLAGS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to make a shared libary?

A

$(CC) -shared $(CFLAGS) module1.o module2.o …. -o libname.so

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Do you need to tell gcc the -L and -l options for dynamic libraries?

A

Yes. It still needs to be able to “search” for a particular dynamic library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you tell the system where to look for a dynamic library?

A

export LD_LIBRARY_PATH=/path/to/library-dir
This can correct the No such file or directory error when loading a shared library.

17
Q

What directories do we want our makefiles to use?

A

build/ to contain binary objects
lib/ to contain all of our libraries
bin/ to contain the executables

Call these
BUILD_DIR = build/$(shell uname -s)-$(uname -m)
LIB_DIR = lib/$(shell uname -s)-$(uname -m)
BIN_DIR = bin/$(shell uname -s)-$(uname -m)

Note that you need to use uname to identify the system.

18
Q

How do you use uname?

A

uname -s for the operating sytem
uname -m for the machine architecture

19
Q

How do you make a directory in a makefile?

A

I.e
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)

20
Q

What does | do in pre-requestites (dependencies)?

A

On the left needs to be up to date (timestamps), but both sides need to exist.
Useful for directories.

21
Q

How do you symbolically link things to the root of the project (where the Makefile is)

A

my_prog: $(BIN_DIR)/my_prog
ln -sf $(BIN_DIR)/my_prog my_prog

-sf is for symbolic force (force updates/re-creates symlink if needed).

22
Q

Where does $(LDFLAGS) go?

A

After $(CFLAGS)

23
Q

How to use -l (lowercase L)

A

-l nameoflib

Says to use libnameoflib.so