A C project links ordinary object files with a static archive, a collection of object files from which the linker can extract individual members. Use this linker model:
The available files contain the following symbols. All symbols are distinct, and no other inputs define or reference them.
File or archive member
Defines
References
main.o
main
read_samples, report
report.o
report
none
libmeter.a member read.o
read_samples
scale
libmeter.a member scale.o
libmeter.a member diagnostics.o
diagnostics
Compare these two input orders:
main.o libmeter.a report.o libmeter.a main.o report.o
For each order, enter the exact integer number of archive members extracted and the exact integer number of distinct symbols still unresolved after all inputs have been processed. Count archive members only in the first answer column.
Unlock full course notes by signing up
Diagnosing an undefined reference
A project has two source files. main.c includes stats.h, which declares double mean(const double *x, int n);, and main.c calls mean. The file stats.c defines mean. A student builds with these commands:
The first two commands succeed without warnings, but the third prints undefined reference to 'mean'. Which explanation and fix is correct?
A macro defined with a zero value
A developer uses the following C source to control which initializers reach the compiler. No command-line options or other source lines change the macro definition.
Complete these statements using decimal integers: after preprocessing, the initializer for retained is ________, and the initializer for level is ________.
Rebuild cost after a nested header edit
A C interpreter project has eight source files: main.c, parse.c, eval.c, print.c, io.c, mem.c, hash.c and log.c. The header types.h contains the line #include "config.h". The files parse.c, eval.c and print.c include types.h, and the files main.c, eval.c and log.c include config.h directly. No other file includes either header. Compiling one source file takes 1.8 s on average, and linking takes 0.9 s. Assume compilations run sequentially, followed by one link, and ignore all other overhead. After you edit config.h, find the number of source files that must be recompiled. Also estimate the rebuild time in seconds, including the link, to one decimal place, and the time saved compared with a full build, in seconds to one decimal place.
Parallel compilation and the final link
A developer measures a clean build of a C program. Compiling sensor.c, filter.c, stats.c, and format.c takes exactly 9 s, 7 s, 5 s, and 3 s, respectively. The four compilations are independent. Linking their object files takes exactly 2 s and starts immediately after all four compilations finish.
Compare two identical build machines, one allowing two compilation jobs at once and the other allowing three. Both use this scheduling rule: at time zero, start as many jobs as possible from the queue sensor.c, filter.c, stats.c, format.c; whenever a slot becomes free, immediately start the next waiting job. Each job occupies one slot until it finishes.
Assume that the stated durations remain unchanged when jobs overlap, and ignore other overhead. Determine: