Combining multi-architecture binaries with lipo and libtool

来源:互联网 发布:金10数据官网 双十一 编辑:程序博客网 时间:2024/06/06 05:58

Combining multi-architecture binaries with lipo and libtool

A problem you don't have every day is finding a way to merge two multi-architecture binary files. In case you find yourself in need for a solution to that particular problem, here is one using lipo andlibtool, both tools available on MacOS X.

Let's assume you have two binary files libFirst.a and libSecond.a. Each contains object files for different architectures. To find out which architectures exactly those are, run lipo -info on them:

> lipo -info libFirst.a libSecond.a
Architectures in the fat file: libFirst.a are: armv7 armv7s
Architectures in the fat file: libSecond.a are: armv7 armv7s

Now, to combine the two library files, you first have to extract individual architectures from each one using lipo -extract:

> lipo -extract armv7 libFirst.a -o libFirst_armv7.a
> lipo -extract armv7s libFirst.a -o libFirst_armv7s.a
> lipo -extract armv7 libSecond.a -o libSecond_armv7.a
> lipo -extract armv7s libSecond.a -o libSecond_armv7s.a

The next step is to use libtool -static to combine the results of the same architecture:

> libtool -static libFirst_armv7.a libSecond_armv7.a -o libCombined_armv7.a
> libtool -static libFirst_armv7s.a libSecond_armv7s.a -o libCombined_armv7s.a

And finally you can use lipo -create to get your final result:

> lipo -create libCombined_armv7.a libCombined_armv7s.a -o libCombined.a

That's it! You have successfully combined two multi-architecture binaries into one.

> lipo -info libCombined.a
Architectures in the fat file: libCombined.a are: armv7 armv7s

Oh, and just in case you're curious how the source code for lipo and libtool look like, here are the links:

  • http://www.opensource.apple.com/source/cctools/cctools-667.3/misc/lipo.c
  • http://www.opensource.apple.com/source/cctools/cctools-667.3/misc/libtool.c
原文:http://www.cvursache.com/2013/10/06/Combining-Multi-Arch-Binaries/

0 0