如何使Boost dylibs在OS X上通用(i386& x86_64)? [英] How to make Boost dylibs universal (i386 & x86_64) on os x?

查看:57
本文介绍了如何使Boost dylibs在OS X上通用(i386& x86_64)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Boost库编译成通用二进制文件(即包含胖"文件,其中包含针对i386和x86_64体系结构的构建).

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).

确保互联网安全和 SO 我整理了以下说明.

Souring the internet and SO I assembled the following instructions.

  1. 下载增强​​版本(例如,从 http://www.boost.org/users/下载/)

在下载的文件夹中,键入 ./bootstrap.sh (或者,在我的情况下为 ./bootstrap.sh --with-libraries = thread ,因为我只需要线程库)

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

类型./b2 install cxxflags =-arch i386 -arch x86"

这些步骤将Boost线程库安装到/usr/local/lib/(其标准位置)中.生成的静态库是通用二进制文件.到目前为止,一切都很好.

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 

但是,动态库似乎仅针对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

我也希望.dylib也具有通用性.有谁知道我如何为i386和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?

推荐答案

我也在为此而苦苦挣扎.诀窍似乎有两个方面.

I was struggling with this as well. The trick seems to be two-fold.

  1. 您需要使用其他 toolset 来构建i386 .dylib.不管我尝试什么, clang 都会构建一个x86_64 .dylib,但是带有正确标志的 darwin 将会构建一个i386 .dylib
  2. 构建两次,一次用于i386,一次用于x86_64;然后使用 lipo 将结果组合成一个胖" .dylib
  1. You need to use a different toolset to build the i386 .dylib. clang will build an x86_64 .dylib no matter what I tried, but darwin with the right flags will build an i386 .dylib
  2. Build twice, once for i386, once for x86_64; then use lipo to combine the result into a "fat" .dylib

这就是我快速提出来以可重复的方式获得胖" .dylibs的东西.在Universal/中找到所需的内容.静态的'fat'.a库保留在stage/lib/中.

Here's what I quick threw together to reproducibly get 'fat' .dylibs. Find the ones you need in universal/. The static 'fat' .a libs are left in 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

这篇关于如何使Boost dylibs在OS X上通用(i386& x86_64)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆