5

I'm trying to compile a Boost library into a universal binary file (i.e. a "fat" file that contains builds for both the i386 and x86_64 architectures).

Souring the internet and SO I assembled the following instructions.

  1. Download boost (e.g. from http://www.boost.org/users/download/)

  2. In the downloaded folder, type ./bootstrap.sh (or, in my case ./bootstrap.sh --with-libraries=thread, since I only need the thread library)

  3. type ./b2 install cxxflags="-arch i386 -arch x86"

These steps installed the Boost thread library to /usr/local/lib/ (its standard location). The resulting static library is a universal binary. So far, so good.

$ lipo -i /usr/local/lib/libboost_thread.a
Architectures in the fat file: /usr/local/lib/libboost_thread.a are: i386 x86_64 

The dynamic library, however, only seems to have been compiled for x86_64.

$ lipo -i /usr/local/lib/libboost_thread.dylib
Non-fat file: /usr/local/lib/libboost_thread.dylib is architecture: x86_64

I'd like the .dylib to be universal as well. Does anyone know how I can compile it for i386 as well as x86_64?

4

1 回答 1

3

我也在为此苦苦挣扎。诀窍似乎是双重的。

  1. 您需要使用不同toolset的来构建 i386 .dylib。clang无论我尝试什么,都会构建一个 x86_64 .dylib,但是darwin使用正确的标志将构建一个 i386 .dylib
  2. 构建两次,一次用于 i386,一次用于 x86_64;然后使用lipo将结果组合成一个“胖” .dylib

这是我快速拼凑起来的内容,可重现地获得“胖”.dylibs。在universal/中找到你需要的。静态 'fat' .a 库留在 stage/lib/ 中。

rm -rf i386 x86_64 universal
./bootstrap.sh --with-toolset=clang --with-libraries=filesystem
./b2 toolset=darwin -j8 address-model=32 architecture=x86 -a
mkdir -p i386 && cp stage/lib/*.dylib i386
./b2 toolset=clang -j8 cxxflags="-arch i386 -arch x86_64" -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in i386/*; do 
  lipo -create -arch i386 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib); 
done

单线:

rm -rf i386 x86_64 universal &&  ./bootstrap.sh --with-toolset=clang --with-libraries=filesystem && ./b2 toolset=darwin -j8 address-model=32 architecture=x86 -a && mkdir -p i386 && cp stage/lib/*.dylib i386 && ./b2 toolset=clang -j8 cxxflags="-arch i386 -arch x86_64" -a && mkdir x86_64 && cp stage/lib/*.dylib x86_64 && mkdir universal && for dylib in i386/*; do lipo -create -arch i386 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib); done
于 2015-06-13T13:09:44.770 回答