How to merge two “ar” static libraries into one?

前端 未结 6 829
悲哀的现实
悲哀的现实 2020-11-22 14:56

I have 2 static Linux libraries, created by ar cr, libabc.a and libxyz.a.
I want to merge them into one static library libaz

6条回答
  •  眼角桃花
    2020-11-22 15:48

    Even better you perform partial linking on each library and them make an archive of the two resulting object files. That way it operates like shared libraries would

    You do partial linking with

    gcc -r --nostdlib
    

    so either instead of making the intermediate archive or after reextracting it, run

    gcc -r --nostdlib $CFLAGS $OBJECTS_A -o $LIBNAME_A.o
    gcc -r --nostdlib $CFLAGS $OBJECTS_B -o $LIBNAME_B.o
    

    then

    ar -cr $LIBNAME_JOINED.a $LIBNAME_A.o $LIBNAME_B.o
    

提交回复
热议问题