I understand that with many processes using a common shared library, the binary code in the shared library can be updated without necessarily having to update all those processes. It's fine as long as it is an internal implementation change, and does not remove exported functions, or change the arguments of exported functions.
I'm not sure how to reconcile this though with Makefile dependencies. The simple guideline is if the file is referenced by any of the commands, then it is a dependency and should be listed as a prerequisite in the Makefile rule.
When linking an executable, it definitely can reference a shared object, and so depend on that shared object. However, it doesn't seem like a relink is always necessary just because the shared object changed.
So I'm wondering about listing library as dependency:
all: process
# listing library.so as dependency
process: file.o library.so
gcc -o process file.o library.so
library.so: library.o
gcc -shared -o library.so library.o
library.o: library.h
vs. not listing it:
all: library.so process
# not listing library.so as dependency
process: file.o
gcc -o process file.o library.so
library.so: library.o
gcc -shared -o library.so library.o
file.o: library.h
library.o: library.h
Suppose library.h
contains declarations for all exported functions from library.so
.
If library.so
is a dependency for process
, then it seems if I only change the implementation of a function (no change to exported function signatures), then I don't need to relink process
, but a make
command would relink library.so
, and then in turn relink process
.
However, if library.so
is not a dependency for process
, then make
would still relink library.so
for an implementation change via the all
target, but not relink process
. If I change the data type of a function argument, add/remove a function argument, or add/remove a function, then library.h
will have a change. This will in turn trigger recompiling file.o
, and in turn trigger relinking process
.
Use of library.h
to control recompile of file.o
, and so indirectly control relink of process
is still imprecise though, because file.o might not actually reference any of the exported functions from library.so that changed.
I reviewed this question, but I couldn't find anything specific about shared object dependencies for a process: Makefile Dependencies, What Should Be a Dependency?