2

As I saw here (Combine static libraries) I may combine more than one static library using libtool

libtool -static -o new.a old1.a old2.a

As far as I know, this will concatenate every single function from the old libraries to the new one. But what I really want are the functions from the new.a library, the others are there for dependency purpose. Is there a way to combine only the part required by the new.a from the other libraries without carrying a bunch of unnecessary code?

Community
  • 1
  • 1
hugos
  • 1,313
  • 1
  • 10
  • 19
  • 1
    Along with dropping the unnecessary code it would be nice to keep the symbols from the old libraries from being exported too. – Mark Ransom Mar 13 '14 at 02:43

1 Answers1

4

You can extract from the old libraries those object files you wish to incorporate in the new. But there really isn't much point in worrying about it; the linker will only link those object files that are necessary, unlike a shared library where all the symbols defined in the shared library are available to the executable (not that it uses them all, usually).

The old-fashioned way to do the job would be:

mkdir new
cd new
ar x ../old1.a
ar x ../old2.a
ar rv ../new.a *.o
cd ..
rm -fr new

After the two x operations, you can weed and whittle the object files to keep what you want for use in new.a.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278