Strip out unneeded libraries
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.. My version info: GNU ld version 2.15.91.0.2 20040727 (SuSE Linux) gcc version 3.3.4 (pre 3.3.5 20040809) -- -Chris Kwasneski Software Engineer Yuma Proving Grounds
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
On Tuesday 03 May 2005 4:34 pm, Chris Kwasneski wrote: 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. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
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
On Tuesday 03 May 2005 5:05 pm, Chris Kwasneski wrote:
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 This is going to cause all 7 libraries to be included.
One possible solution is to make your libraries shared objects. Then they will only be used at run time. In theory, only those libraries that have symbols required by your objects should be linked in. if you have 2 libraries, lib1 and lib2. lib1 contains the definition for function foo and bar, and lib2 contains the definitions for fubar and barfu. You have a C file that references foo: The gcc -o foobar foobar.c -llib1 -llib2 In this case only lib1 SHOULD be pulled in. But, as I mentioned before, be careful not to reference anything in lib2 from foo.c. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
participants (2)
-
Chris Kwasneski
-
Jerry Feldman