Jerry Feldman wrote:
On Tuesday 03 May 2005 4:34 pm, Chris Kwasneski wrote:
I have 50 odd utility programs that are all part of one 'system'. I currently have a make file that cascade builds each one from a higher level directory. Each program is in its own directory, and has its own makefile. Each program uses 4 (ish) of 7 libraries. Each program using a different set of 4 out of the 7l. What I'd like to do is place the list of 7 libraries in a higher make file and include them at the lower make file.
However, when I build them, I currently get all 7 libraries linked in, even though the program needs only 4. Is there a way to tell gcc or ld to trim unused libraries?
I did a search, and I found a -strip-dead for ld, but it doesn't seem to work. I also tried --no-whole-archive, and a -Wl switch that escapes me right now..
What does your CFLAGS or LDFLAGS look like? Or, when you link a program: gcc -o <progname> -L<library directory> foo.o -llib1 -llib2 -llib5 -llib7 The -l (lower case l) is what will incorporate the libraries into each program. In the above case, you should only draw in the listed 4 libraries. Alternatively: gcc -o <progname> -L<library directory> foo.o lib1.a, lib2.a, lib5.a, lib7.a
You've also got to be careful that the libraries do not reference eachother.
Assuming a directory of src with prog1, prog2 directories under it I'd like to be able to do this: src/Makefile.inc: LIBS = -llib1 -llib2 -llib3 -llib4 -llib5 -llib6 -llib7 And then in each directory (prog1, prog2...) makefile: include ../Makefile ... gcc -o $(PROGRAM) $(libs) -Xlinker --strip-unused-libs That way I only have to write the libs directive out once, instead of 50 times, and just use the include and strip statements to make sure each program only links with whichever libs it really needs. Instead of each make file having a separate compile line. -- -Chris Kwasneski Software Engineer Yuma Proving Grounds