I was working on a C ++ project that references a .so (dynamic library) file. Suppose I have a target PROG that should reference a.so, and a.so is also built by me, as indicated in the following Makefile.
PROG_SRCS = prog.cpp
PROG_OBJS = $(PROG_SRCS: %.cpp:%.o)
all: PROG
PROG: $(PROG_OBJS) liba.so
$(LINK.cpp) -o $@ $(PROG_OBJS) -la
LIBA_SRCS = liba/a.cpp
LIBA_OBJS = $(LIBA_SRCS: %.cpp:%.o)
liba.so: $(LIBA_OBJS)
$(LINK.cpp) -shared -Wl.-soname,$@ -o $@ $^
I used auto-dependency generation to get .cpp files to get their own dependency on .h files. And prog.cpp includes ah
But in this way, as soon as I change a.cpp, liba.so will be redone, then PROG will be a remake (relink), which I do not want. I am just modifying the liba.so implementation, but not any interface definitions. PROG should just redo after changing ah
, a.so , PROG, a.so PROG.
Makefile - , ,
( ).
ORDER = /tmp/.ORDER
all: PROG
PROG: $(PROG_OBJS) $(ORDER)
$(LINK.cpp) -shared -Wl,-soname,$@ -o $@ $(PROG_OBJS) -la
$(ORDER): liba.so
test -e $@ || touch $@
, , liba.so , $(ORDER) .
, .
- , . tmp.