为iphone 及iphone simulator编译boost库

1 下载boost,解压到/Users/test/Downloads/boost_1_49_0

2 cd /Users/test/Downloads/boost_1_49_0

3 打开terminal控制台,键入su然后输入管理员密码,再键入vi ./build.bat

4 在控制台里录入以下内容:

 #! /bin/sh
#PREFIX=/libs
#echo ${PREFIX}
#ls /usr/local
echo 'now start install boost.build'
#cd tools/build/v2/
#chmod +x ./bootstrap.sh
#./bootstrap.sh
#b2 install --prefix=/libs
#DOWNLOADS=/Users/test/Downloads/
#SDK_VERSION="4.3"
#./bjam --with-regex --toolset=darwin architecture=x86 target-os=iphone define=_LITTLE_ENDIAN  link=static stage
# ${DOWNLOADS}boost_1_49_0/tools/build/v2/engine/bin.macosxx86_64/b2 --with-regex --layout=versioned --includedir=/libs/include/ --libdir=/libs/lib/i386 --build-type=minimal toolset=intel-darwin stage

#

# 只编译regex

#./bootstrap.sh --with-libraries=regex

#编译所有的库

./bootstrap.sh

# 编译arm库,真机用

./bjam --layout=versioned --build-type=complete toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-4.3 define=_LITTLE_ENDIAN link=static debug release stage

#编译i386库,模拟器用

./bjam --layout=versioned --build-type=complete toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-4.3 link=static debug release stage

5 按Esc 然后键入:wq 也就是保存退出

6 在控制台里键入chmod +x ./build.bat,

7 用文本编辑器打开/Users/test/Downloads/boost_1_49_0/tools/build/v2/user-config.jam

找到#using gcc附近,加入以下内容,注意#表示注释,意思是指定编译器及其参数,我测试时只打开了编译iphonesimulator部分,开始用的c++编译器是g++-4.2,后来生成的代码好像会报code generation错误,我也不确定是不是编译器的问题,就换了llvm-g++-4.2,因为xcode里默认用llvm-gcc编译器,所以这里先用这个,如果也要编译iphone真机能跑的boost,需要指定-arch armv7

 

using darwin : 4.2.1~iphone
   : /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 -arch armv7 -mthumb -fvisibility=hidden -fvisibility-inlines-hidden
   : <striper>
   : <architecture>arm <target-os>iphone
   ;
 #<macosx-version>iphone-4.3
using darwin : 4.2.1~iphonesim
   : /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-g++-4.2 -arch i386 -fvisibility=hidden -fvisibility-inlines-hidden
   : <striper>
   : <architecture>x86 <target-os>iphone
   ;
# <macosx-version>iphonesim-4.3
#   ;

 

 8 用文本编辑器打开/Users/test/Downloads/boost_1_49_0/tools/build/v2/tools/darwin.jam,在最上方加入

 

 ## The MacOSX versions we can target.
.macosx-version =
    10.6 10.5 10.4 10.3 10.2 10.1
    iphone-4.3 iphonesim-4.3
    iphone-3.2 iphonesim-3.2
    iphone-3.1.3 iphonesim-3.1.3
    iphone-3.1.2 iphonesim-3.1.2
    iphone-3.1 iphonesim-3.1
    iphone-3.0 iphonesim-3.0
    iphone-2.2.1 iphonesim-2.2.1
    iphone-2.2 iphonesim-2.2
    iphone-2.1 iphonesim-2.1
    iphone-2.0 iphonesim-2.0
    iphone-1.x
    ;

不过我感觉这一块不加也应该可以,

9 在命令行里执行./build.bat,过一会可以在 /Users/test/Downloads/boost_1_49_0/stage里找到 libboost_regex.a

 如果在引用boost静态库里报以下错误(debug版本的demo程序应该引用debug版本的boost库,release版本的demo程序应该引用release版本的boost库,不然就会出现这种错误):

bad codegen, pointer diff in void boost::throw_exception<std::logic_error>(std::logic_error const&)to global weak symbol boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >::~clone_impl()for architecture i386

可以将projects和targets的build-settings->llvm-gcc 4.2-code generation ,将Symbols Hidden By Default的值设为yes,然后重新编译即可

如果再出现以下错误:

Code Sign error: The identity 'iPhone Developer' doesn't match any valid cer

可以重新建一个demo项目再试试看,我重新建了一个项目就好了。

参考网址:

http://paulsolt.com/2010/04/c-logging-and-building-boost-for-iphoneipad-3-2-and-macosx/

原文链接: https://www.cnblogs.com/yuanxiaoping_21cn_com/archive/2012/05/25/2518681.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    为iphone 及iphone simulator编译boost库

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/51173

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午2:43
下一篇 2023年2月9日 上午2:43

相关推荐