Combine static libraries

I tried the approach in this question, but it seems the linux version of ar is not the same as the mac version since I failed to combine the object files again.

What I basically want to do is is merge another static library into my Xcode static library build product via a run-script build phase.

Unfortunately I can't compile the other library directly into my project because it has it's own build system (therefore I use the compiled libs).

I think it should be possible to merge the other library via ar into the Xcode generated library without decompiling the build product. How do I accomplish this?


你可以使用libtool来做到这一点

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/bash

INPATH="path/to/source/libs"

LIBPREFIX="lib"
LIBS="one two three"
LIBEXT=".a"

OUT="combined"

ARCHS="armv7 armv7s arm64"

for arch in $ARCHS
do
  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 $INLIBS
done

OUTLIBS=`eval echo $LIBPREFIX$OUT-{${ARCHS// /,}}$LIBEXT`
lipo -create $OUTLIBS -o $LIBPREFIX$OUT$LIBEXT
rm $OUTLIBS

You should just be able to link one to the other. So... just use ld to merge the images.

链接地址: http://www.djcxy.com/p/67118.html

上一篇: 使用Xcode 6.1.1的静态库和cocoapods

下一篇: 组合静态库