Combine static libraries on Apple
you can use libtool
to do it
libtool -static -o new.a old1.a old2.a
If you're dealing with multi-architecture static libraries, a bit of extra manipulation is required to thin each library, combine the thinned versions, and then fatten the result. Here's a handy script which you can edit to your satisfaction which does all that in one. The example takes three iOS libraries path/to/source/libs/libone.a
, path/to/source/libs/libtwo.a
, and path/to/source/libs/libthree.a
and merges them into a single library libcombined.a
.
#! /bin/bashINPATH="path/to/source/libs"LIBPREFIX="lib"LIBS="one two three"LIBEXT=".a"OUT="combined"ARCHS="armv7 armv7s arm64"for arch in $ARCHSdo for lib in $LIBS do lipo -extract $arch $INPATH/$LIBPREFIX$lib$LIBEXT -o $LIBPREFIX$lib-$arch$LIBEXT done INLIBS=`eval echo $LIBPREFIX\{${LIBS// /,}\}-$arch$LIBEXT` libtool -static -o $LIBPREFIX$OUT-$arch$LIBEXT $INLIBS rm $INLIBSdoneOUTLIBS=`eval echo $LIBPREFIX$OUT-\{${ARCHS// /,}\}$LIBEXT`lipo -create $OUTLIBS -o $LIBPREFIX$OUT$LIBEXTrm $OUTLIBS
You should use ar -r
to create an archive on MacOS:
ar -x libabc.aar -x libxyz.aar -r libaz.a *.o