One way to accommodate multiple libraries with distinct dependencies in a Makefile target is to create separate sub-targets for each library and its specific dependencies. Then, use these sub-targets to build the libraries and link them together into the final executable.
For example, consider two libraries, libfoo and libbar, where libfoo depends on libbaz and libbar depends on libqux. Here's an example Makefile target:
all: myprogram
libfoo:
cd libfoo && $(MAKE)
libbar:
cd libbar && $(MAKE)
myprogram: libfoo libbar
gcc -o myprogram main.c -Llibfoo -Llibbar -lfoo -lbar -lbaz -lqux
This Makefile has three targets: libfoo
, libbar
, and myprogram
. The libfoo
and libbar
targets build each library separately, using their own dependencies. The myprogram
target depends on libfoo
and libbar
, and links all the libraries together with the main code.
This way, each library can be built with its specific dependencies and the final program can use them all together.
Asked: 2023-01-18 11:00:00 +0000
Seen: 12 times
Last updated: Jan 07 '22