xcode 结合静态库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8170450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Combine static libraries
提问by Erik Aigner
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.
我尝试了这个问题中的方法,但似乎 linux 版本ar
与 mac 版本不同,因为我未能再次组合目标文件。
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.
我基本上想做的是通过运行脚本构建阶段将另一个静态库合并到我的 Xcode 静态库构建产品中。
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?
我认为应该可以将其他库 via 合并ar
到 Xcode 生成的库中,而无需反编译构建产品。我该如何实现?
回答by Bruce
you can use libtool
to do it
你可以用libtool
它来做
libtool -static -o new.a old1.a old2.a
回答by bleater
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
.
如果您正在处理多架构静态库,则需要一些额外的操作来精简每个库,组合精简的版本,然后使结果变胖。这是一个方便的脚本,您可以对其进行编辑以满足您的需求,它可以同时完成所有操作。该示例采用三个 iOS 库path/to/source/libs/libone.a
, path/to/source/libs/libtwo.a
, 并将path/to/source/libs/libthree.a
它们合并为一个库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
回答by sergio
You should use ar -r
to create an archive on MacOS:
您应该使用ar -r
在 MacOS 上创建存档:
ar -x libabc.a
ar -x libxyz.a
ar -r libaz.a *.o
回答by justin
You should just be able to link one to the other. So... just use ld
to merge the images.
您应该能够将一个链接到另一个。所以...只是ld
用来合并图像。