11

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.

Rotsiser Mho
  • 551
  • 2
  • 5
  • 19
  • 1
    I'm in the same boat as you, and I would like to know whether you or someone had finally solved this. From what I know, "-ftemplate-depth-128: command not found" is probably the result of a blank substitution of a compiler, as in the following: ${COMPILER} -ftemplate-depth-128 Which is why the error makes it sound like ftemplate-depth-128 is intended as a command. – Aldrich Co Jul 20 '13 at 14:37
  • I haven't yet found a solution unfortunately. I believe the compiler command is supposed to be set in ${CONFIG_COMMAND}. For the iOS builds for the actual device lines like this appear in the debug output: `toolset.handle-flag-value /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++` shortly after a line that says: `get .darwin.variable.295 = CONFIG_COMMAND`. – Rotsiser Mho Jul 21 '13 at 23:11
  • Which version of XCode are you using? – Brent Aug 25 '13 at 16:01
  • I'm using Xcode 4.6.3 – Rotsiser Mho Aug 25 '13 at 19:59

4 Answers4

7

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
Ako
  • 956
  • 1
  • 10
  • 13
  • 1
    OK, just trying to help with question: http://stackoverflow.com/questions/18888327/using-boost-on-xcode-5-apple-llvm-5-0 but I'm getting the following error using Xcode 5 DP6 under OSX 10.8: `boost.sh: line 252: /Users/andy/Applications/Xcode5-DP6.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin//ar: No such file or directory`. Any idea how to fix this? – trojanfoe Sep 19 '13 at 08:53
  • 1
    @trojanfoe I was having the same issue after running boost.sh the first time. The following seemed to help me (in that my machine is now busily building code instead of hanging on a lipo call): `cd` to `{generated src dir}/boost_1_54_0/` Run `./bootstrap.sh toolset=clang` Rerun `boost.sh` – matthias Oct 08 '13 at 05:55
  • Actually, it looks like the script expects to find a version of `ar` in the bin folders for iphoneos and iphonesimulator. That's not necessarily the case. That assumption should be replaceable with an invocation to xcrun --sdk={iphoneos | iphonesimulator } – matthias Oct 08 '13 at 06:47
  • 1
    Here's a gist with the changes. Seems to work for me. https://gist.github.com/payco/6880661 I'm now running into Semantic Issues all over the standard library, but I think that's something deciding not to compile libc++ headers with c++11. – matthias Oct 08 '13 at 07:02
  • 3
    Great work. I extended @matthias's script to build for arm64 and x86_64 too. Here's the gist: https://gist.github.com/rsobik/7513324 – rsobik Nov 17 '13 at 13:22
4

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
   ;
Erik Hvatum
  • 301
  • 3
  • 7
  • I'm interested to know more. The change to the b2 arguments you posted, does that create a .framework file like the script mentioned? – Aldrich Co Sep 03 '13 at 02:57
  • Erik, with your b2 arguments I am not able to build for architecture i386, just tested today with boost 1.54. – tetuje Sep 03 '13 at 12:38
  • tetuje, I suggest trying it with the following in your ~/user-config.jam: (not enough space here, look at my edits above) – Erik Hvatum Sep 16 '13 at 06:54
  • 1
    Aldrich Co, my arguments don't make a framework. I think making a framework is mostly a matter of putting all the boost headers and libs in the right places in a directory structure and merging libs. Merging the libs is a bit tricky due to some of the individual .a files b2 creates containing object files with the same name; duplicates need to be renamed as you merge... Note that the .sh file posted above does not do this and will have issues if you need codecvt. I ended up writing a python script to work around this. If you need it, I'll check if I can share it (I wrote it at work). – Erik Hvatum Sep 16 '13 at 07:07
4

Based on responses in this post and scripts created by other people I put together a bash script that builds boost framework for iOS and OSX with Xcode 5, that means for armv7, armv7s, arm64, i386 and x86_64.

Check it out here https://github.com/mgrebenets/boost-xcode5-iosx.

I know for sure it builds boost starting with 1.49.0

i4niac
  • 1,684
  • 1
  • 17
  • 20
  • Thanks for this! But it seems I am having some issues (commands extracted from bjam output): g++ -x assembler-with-cpp -arch armv7 -o make_arm_aapcs_macho_gas.o -c make_arm_aapcs_macho_gas.S The above seems working, but g++ -x assembler-with-cpp -arch arm64 -o make_arm_aapcs_macho_gas.o -c make_arm_aapcs_macho_gas.S just doesn't compile: make_arm_aapcs_macho_gas.S:52:18: error: invalid variant 'save' mov a4, a1 @ save address of context stack (base) A4 Any insights? – Dejavu Feb 11 '14 at 01:04
0

For those interested in keeping up to date:

You can use the BOOST 1.57.0 with ofxiOSBoost static libraries and headers: https://github.com/danoli3/ofxiOSBoost

Releases for libc++ (c++11), libstdc++.

All build scripts are in the /scripts folder (updated Peter Goodliffe script)

Danoli3
  • 3,203
  • 3
  • 24
  • 35