Building boost on Mac OS X 10.6 with XCode 3.2

Getting boost to build in ‘fat binaries’ is a pain when you’ve just switched to XCode 3.2. Switching to XCode 3.2 is somewhat obligatory, because that also brings you the SDK for Mac OS X 10.6, aka Snow Leopard. And when you run the Snow Leopard, you want the SDK for it as well. It sounds so simple.

The Apple version of gcc, included in XCode, stops building boost in fat versions, it works for targeted versions (i.e. with only one architecture). But, if you want to build ‘universal’ binaries that work in 64bit and 32bit mode, you’re out of luck.

I got it to build this morning, thanks to some discussions on the boost mailing list. And it == boost 1_40_0, with XCode 3.2 on Snow Leopard.

This is the command-line I used:

bjam --build-dir=../boost_build --layout=versioned toolset=darwin architecture=combined address-model=32_64 link=shared,static install

And here is the patch I created to get it to work. It boils down to: remove all the ppc entries from the tools/build/v2/tools/darwin.jam, because the XCode compiler does not offer support for PPC anymore. And, you have to remove the “-m64” option in the gcc.jam, because the xcode compiler does not like to have -arch x86_64 -arch i386 -m64 all together on the command-line.

But, if you take the road of building your code on XCode 3.2, you specifically eliminate all those users still using a PPC based Mac. That might not be what you intended. In that case you probably need to add the -V 4.0.1. option to gcc/g++ in which case you use the older compiler (from XCode 3.1), which might or might not be what you need for your project.

(Sorry for the stupid looks on the patch, but wordpress mangles stuff with the <code> tag).

diff --recursive -u boost_1_40_0.orig/tools/build/v2/tools/darwin.jam boost_1_40_0/tools/build/v2/tools/darwin.jam
--- boost_1_40_0.orig/tools/build/v2/tools/darwin.jam 2009-04-14 09:59:30.000000000 +0200
+++ boost_1_40_0/tools/build/v2/tools/darwin.jam 2009-09-06 08:01:26.000000000 +0200
@@ -304,9 +304,9 @@
: $(values) ;

-arch-addr-flags darwin OPTIONS : combined : 32 : -arch i386 -arch ppc : default ;
-arch-addr-flags darwin OPTIONS : combined : 64 : -arch x86_64 -arch ppc64 ;
-arch-addr-flags darwin OPTIONS : combined : 32_64 : -arch i386 -arch ppc -arch x86_64 -arch ppc64 ;
+arch-addr-flags darwin OPTIONS : combined : 32 : -arch i386 : default ;
+arch-addr-flags darwin OPTIONS : combined : 64 : -arch x86_64 ;
+arch-addr-flags darwin OPTIONS : combined : 32_64 : -arch i386 -arch x86_64 ;

arch-addr-flags darwin OPTIONS : x86 : 32 : -arch i386 : default ;
arch-addr-flags darwin OPTIONS : x86 : 64 : -arch x86_64 ;
diff --recursive -u boost_1_40_0.orig/tools/build/v2/tools/gcc.jam boost_1_40_0/tools/build/v2/tools/gcc.jam
--- boost_1_40_0.orig/tools/build/v2/tools/gcc.jam 2009-07-11 13:04:31.000000000 +0200
+++ boost_1_40_0/tools/build/v2/tools/gcc.jam 2009-09-06 08:11:17.000000000 +0200
@@ -375,7 +375,8 @@
- option = -m64 ;
+ # option = -m64 ;
+ option = ;
OPTIONS on $(targets) += $(option) ;

About these ads

13 responses to “Building boost on Mac OS X 10.6 with XCode 3.2

  1. Actually you can (and should) leave in references to “ppc” as these will still work. Only the “ppc64″ references need to be removed (as Apple makes no ppc OS that is 64 bit). This way your code will be Universal (and work on old 32 bit ppc machines)*.

    Please note that I am speculating on the “work” bit, having only confirmed that this will compile properly (and create a Universal binary).

  2. This really needs to be cleared up. You CAN use the 10.5 SDK and deploy on 10.6.

    You can BUILD 64 Bit PPC binaries. People do need this support. Doesn’t matter is Apple shipped a truly 64 bit PPC system. The fact is that you can build a 64 bit PPC binary and run it on a PPC system (G5 based system).

    Stripping out all the -m64 is a BIG mistake as it may still be needed for developers to target a 64 bit PPC machine running 10.5

    Mike Jackson

    • Mike, thanx for you comment. You are right, however, one cannot have -m64 and -arch x86_64 (or ppc64) on the same command line with gcc 4.2.1, as included in Xcode by Apple. However, I’ll try and update the patch to just eliminate the -m64 option.

    • I will just make the point that “Standard 32/64 Universal” builds in Xcode are not ppc64 compatible.

      Also, I did not seem to be able to sucesssfully create a boost build on a 10.6 machine without removing the m64 option. Mike seems to be saying that it is possible on a 10.5 machine, but building on a 10.6 machine did not work (at least for me).

  3. You _should_ be able to make full quad binary on 10.6 if you use the 10.5 SDK which has PPC support in it. You would need to set the SDKROOT to the 10.5 SDK and set the minimum OS X deployment target to 10.5.
    Due to other reasons I have not been able to upgrade to 10.6 but speaking with other developers who _do_ have 10.6 they say this should be possible and in fact 1 developer is in fact creating quad binaries under 10.6. probably needs an update.

  4. A simple solution for building for Intel i386 and x86_64 with no PowerPC support was to comment out the line with the “-m64″ option in build/v2/tools/gcc.jam.

    Then just add these options to your bjam command line:

    architecture=x86 address-model=32_64 –build-type=complete –layout=versioned

    I did not have to remove anything relating to the PowerPC options, as I manually chose x86 as the architecture.

  5. I’m having a hellish time trying to build the python bindings for boost in Snow Leopard. I’m using boost_1_42_0, which seems to build okay (except for hanging on test), and I’ve downloaded bgl-python-0.9 (the boost python bindings), but the build instructions seem to be old and don’t reflect the contents of bgl-python-0.9.

    I’ve been banging my head against the wall trying to get this library up and running. I really need a system that can help me calculate betweenness centrality on a dataset I have.

    Has anyone successfully installed boost with its python bindings on Snow Leopard?

    Are there any other network graph libraries out there for python (or Java) that can calculate betweenness well?



  6. Thanks for the info, but bjam will not accept the –layout or option. It returns “unknown option” for that when you try it.

    • Hmm, that’s weird. Did you use the bjam that came with boost 1.42, or did you use an older version? I have tried the commandline with boost 1.37 and 1.40 as well and these versions both start building with the mentioned commandline.

      • Yep, it’s 1.42. It didn’t like anything with the double hyphens. The other parameters worked fine. And I did apparently get a properly combined 32/64 binary.

        All I did was comment out the line with the “-m64″ option in tools/build/v2/tools/gcc.jam as noted by someone above (don’t know if that step was needed). Then I added this to my bjam command:

        toolset=darwin architecture=x86 address-model=32_64 link=shared,static install

        Before that I used the bootstrap option-setter to select a few libraries and set the installation directory.

        I’ll probably be building some more later, so I’ll follow up if I discover anything new. Thanks for your response.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s