Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compile Boost 1.54.0 (1.54) for the iOS simulator (6.1) on OS X 10.8.4?

I have successfully managed to compile several of the Boost libraries and create a framework for use with OS X, iOS, and the iOS simulator using this script: https://github.com/wuhao5/boost/blob/188e905626dbd522f65950102ed0c8ce77cb28e8/boost.sh based on Peter Goodliffe's work here: http://goodliffe.blogspot.com/2010/09/building-boost-framework-for-ios-iphone.html with Boost 1.53.0 using clang and linking against libc++.

The script fails when compiling for the iOS simulator with Boost 1.54.0 with the following error:/bin/sh: line 1: -ftemplate-depth-128: command not found.

I did quite a bit of digging and here is what I know:

  • In boost.sh, the iOS simulator bjam and compiler options include "-arch i386"
  • The release notes for Boost 1.54.0 state that "Boost no longer supports the 80386 target CPU"
  • Boost 1.53.0 appears to compile fine for OS X, iOS, and the iOS simulator using the same script
  • Boost 1.54.0 appears to compile fine for OS X and iOS itself using the same script

Here is what I think I know:

  • When passing "-d13" to bjam (to generate debug information), it appears that the variable "CONFIG_COMMAND" is not being set when building for the iOS simulator. For the other configurations, this variable is set to the path to clang and includes the compiler options. For the simulator, it is empty which I believe leads to the error above as when bjam attempts to run the compiler using this variable, it instead runs some appended options which begin with the template depth. Therefore, the CONFIG_COMMAND variable does not appear to be being set properly causing the failure.

I have no idea why it's not being set as I don't know enough about the Boost build system to sift through the rest of the 100+MB output it generated with the "-d13" flag. I suspect an incompatibility with the "-arch i386" option was introduced with 1.54.0. I've tried changing this to "-arch i486" and "-arch x86_32" but the same problem occurs.

Has anyone else had success with this? I'd like to use Boost.Log which is why I'm even attempting this.

like image 321
Rotsiser Mho Avatar asked Jul 18 '13 04:07

Rotsiser Mho


2 Answers

I got it building with the boost.sh given here by changing the line in buildBoostForiPhoneOS()

./bjam -j16 --build-dir=iphonesim-build --stagedir=iphonesim-build/stage --toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-${IPHONE_SDKVERSION} link=static stage

to

./bjam -j16 --build-dir=iphonesim-build --stagedir=iphonesim-build/stage --toolset=darwin-${IPHONE_SDKVERSION}~iphonesim architecture=x86 target-os=iphone macosx-version=iphonesim-${IPHONE_SDKVERSION} link=static stage

Modified boost.sh with Boost pkg download and unpacking. Just need to run and all done!

Boost 1.54
MacOSx 10.8.4
Xcode 4.6.3
like image 169
Ako Avatar answered Oct 22 '22 07:10

Ako


I figured this out a while ago by reading through diffs of every single jam file between boost 1.53.0 and 1.54.0, which was a serious undertaking. I meant to post a patch, but just finding the cause took time I didn't have, and now I don't remember what it was.

At any rate, I DO remember the quick fix I used to move along and meet a deadline. It is, for boost 1.54.0, to supply bjam with the "toolset=darwin-[version]~iphonesim" argument. You can also give arm builds toolset=darwin-[version]~iphone, though it doesn't need it.

For example, using the iOS 6.1 SDK:

./b2 toolset=darwin-6.1~iphonesim architecture=x86 target-os=iphone macosx-version=iphonesim-6.1 link=static variant=debug  define=BOOST_TEST_NO_MAIN define=BOOST_TEST_ALTERNATIVE_INIT_API linkflags="-stdlib=libc++" -j2 -d+2 -sICU_PATH=/usr/local/icu --without-python --layout=tagged --build-dir="/Users/wix/Desktop/boost_1_54_0/_build/simd_build" --stagedir="/Users/wix/Desktop/boost_1_54_0/_build/simd_stage" --debug-configuration stage

If this doesn't work for you, let me know and if I have a moment I'll get the old build dir off backup to see if there's anything else I did. The command above is from my histfile.

Also, FYI, to make the ICU check pass for arm builds targeting only v7 and v7s with ICU libs built likewise, apply the following patch to tools/build/v2/tools/darwin.jam:

460,464c460,465
<             if $(instruction-set) {
<                 options = -arch$(_)$(instruction-set) ;
<             } else {
<                 options = -arch arm ;
<             }
---
>             #if $(instruction-set) {
>             #    options = -arch$(_)$(instruction-set) ;
>             #} else {
>             #    options = -arch arm ;
>             #}
>       options = -arch armv7 ;

Also, more generally, you may need something like the following in your ~/user-config.jam:

using clang : : : <cxxflags>"-std=c++11 -stdlib=libc++" <linkflags>"-stdlib=libc++" ;

using darwin : 6.1~iphone
   : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch armv7 -arch armv7s -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11 -stdlib=libc++ -miphoneos-version-min=5.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
   : <striper> <root>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
   : <architecture>arm <target-os>iphone
   ;

using darwin : 6.1~iphonesim
   : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch i386 -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11 -stdlib=libc++ -miphoneos-version-min=5.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk
   : <striper> <root>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
   : <architecture>x86 <target-os>iphone
   ;

Also, for boost::context to build correctly for the simulator, I needed to add the following to libs/context/build/Jamfile.v2:

alias asm_context_sources
   : asm/make_i386_sysv_macho_gas.S
     asm/jump_i386_sysv_macho_gas.S
   : <address-model>32
     <architecture>x86
     <binary-format>mach-o
     <target-os>iphone
     <toolset>darwin
   ;
like image 21
Erik Hvatum Avatar answered Oct 22 '22 09:10

Erik Hvatum