Boost logo

Boost-Build :

Subject: Re: [Boost-build] Patch for building Boost 1.40 on Mac OS X Snow Leopard
From: Boris Dušek (boris.dusek_at_[hidden])
Date: 2009-10-22 09:13:39


Hi, I wrote this reply some time ago, but now it's also relevant:

On Thu, Oct 22, 2009 at 11:13 AM, Vladimir Prus <ghost_at_[hidden]> wrote:
>
> I am still trying to figure the right magic to disable -ppc64 when
> using 10.6 SDK. Am I right that ppc64 is not supported with 10.6
> regardless of whether you are building a fat library, or not? In other
> words, does explicit
>
> address-model=64 architecture=power
>
> have any chance of working?
>
> short answer: no
long answer: (sorry if this is already known)

I second the request for a patch for this issue to get into the next
> release, at least the portion of the patch that removes the -m64 option from
> the command line.
>

the "at least the -m64 portion" is important, since for the other portion of
the patch, the statement "gcc-4.2 from the Developer Tools package Apple
released for Snow Leopard cannot compile -arch ppc64 for any target version
of OS X" is not true. I have done some experimentation quite some time ago
and while I don't remember for sure, I think the combination of _both_ gcc
version (selected on command-line by typing g++-4.0 or g++-4.2) and the
MacOSX10.<version>.sdk (selected with bjam via macosx-version and
macosx-version-min, and with bar command-line by
-mmacosx-version-min=10.<version> and -isysroot
/Developer/SDKs/MacOSX10.<version>.sdk) determines whether gcc-4.2 is able
to compile -arch ppc64 binary.

Try it yourself with a minimal test.cpp of your own making, including a few
standard header files:

This works on Snow Leopard, because there is nothing really snow-leopard
specific to it - everything is used like if you were compiling on Leopard
with no special flags:
g++-4.2 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk/
-arch ppc64 test.cpp -o test

The following does not work (even for -arch i386), since GCC 4.2 was not
available on Tiger, and so GCC's internal headers for the 4.2 version are
not available in the Tiger (10.4) SDK:
g++-4.2 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk/
-arch ppc64 test.cpp -o test
test.cpp:1:20: error: iostream: No such file or directory
test.cpp:2:19: error: cstdlib: No such file or directory

If you do the above with a file that does not use any C++ standard headers
(i.e. int main(){ return 0; }), it does produce an executable that works!

And this does not work, since on Snow Leopard, GCC 4.2 is available along
with its internal headers, but the internal headers specially for -arch
ppc64 are missing, since Snow Leopard itself does not run on ppc, and ppc is
probably not supported via the Rosetta ppc emulator for Intel processors:
g++-4.2 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk/
-arch ppc64 test.cpp -o test
In file included from test.cpp:1:
/Developer/SDKs/MacOSX10.6.sdk//usr/include/c++/4.2.1/iostream:44:28: error:
bits/c++config.h: No such file or directory
In file included from
/Developer/SDKs/MacOSX10.6.sdk//usr/include/c++/4.2.1/ios:43,
                 from
/Developer/SDKs/MacOSX10.6.sdk//usr/include/c++/4.2.1/ostream:45,
                 from
/Developer/SDKs/MacOSX10.6.sdk//usr/include/c++/4.2.1/iostream:45,
                 from test.cpp:1:
/Developer/SDKs/MacOSX10.6.sdk//usr/include/c++/4.2.1/iosfwd:45:29: error:
bits/c++locale.h: No such file or directory
... (much more lines)

the bits/* files are present in a platform-specific internal header, and
ppc64 is missing:
find /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.0.0/ -name c++locale.h
/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.0.0//i686-apple-darwin10/bits/c++locale.h
/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.0.0//powerpc-apple-darwin10/bits/c++locale.h
/Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.0.0//x86_64-apple-darwin10/bits/c++locale.h

ppc64 bits/* files are present in the 10.5 and 10.4u SDK.

I tried now the same experiment with g++-4.0: works for 10.4u and 10.5 SDKs
without problem, for 10.6 compilation works (unlike g++-4.2), but linking
fails, since on Snow Leopard, system libraries are only 3-way: i386 x86_64
ppc, i.e. ppc64 is missing:
g++-4.0 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk/
-arch ppc64 test.cpp -o test
ld: warning: in /Developer/SDKs/MacOSX10.6.sdk//usr/lib/crt1.10.5.o, missing
required architecture ppc64 in file
ld: warning: in
/Developer/SDKs/MacOSX10.6.sdk//usr/lib/powerpc-apple-darwin10/4.0.1/libstdc++.dylib,
missing required architecture ppc64 in file
ld: warning: in /Developer/SDKs/MacOSX10.6.sdk//usr/lib/libgcc_s.10.5.dylib,
missing required architecture ppc64 in file
ld: warning: in /Developer/SDKs/MacOSX10.6.sdk//usr/lib/libSystemStubs.a,
missing required architecture ppc64 in file
ld: warning: in /Developer/SDKs/MacOSX10.6.sdk//usr/lib/libSystem.dylib,
missing required architecture ppc64 in file
Undefined symbols:
  "_fdopen", referenced from:
      _main in cckrrB6h.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int)in cckrrB6h.o
  "___gxx_personality_v0", referenced from:
      ___gxx_personality_v0$non_lazy_ptr in cckrrB6h.o
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_0 in cckrrB6h.o
  "___cxa_atexit", referenced from:
      __static_initialization_and_destruction_0(int, int)in cckrrB6h.o
  "_fwrite", referenced from:
      _main in cckrrB6h.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

So to sum-up: Apple's developer tools contain only one g++-4.0 binary and
only one g++-4.2. They also contain one SDK for each Mac OS X version for
which it supports cross-compiling. These SDKs each contain system header
files, system libraries, and gcc's internal headers (C++ standard library
headers). The single g++-4.x binary uses, based on the SDK selected with
-isysroot (macosx-version in boost.build), for linking different libraries
and object files and for compiling different internal (and system) headers.
Successful compilation with -arch ppc64 depends both on which g++ version
you use (4.0 or 4.2) and which OS version you are (cross-)compiling for:

g++-4.2:
10.4 SDK: does not work for any arch (gcc 4.2 simply was not available in
Tiger, C++ internal headers for 4.2 missing)
10.5 SDK: all archs work
10.6 SDK: -arch ppc64 does not work (Snow Leopard does not support running
ppc64 executables ("Bad CPU type in executable"), it does support running
ppc executables via Rosetta; and on Snow Leopard, system libraries are only
3-way: i386 x86_64 ppc; ppc64 is missing)

g++-4.0:
10.4 SDK: all archs work (but beware that not all system libraries are
4-way, some are only 2-way (32-bit) - see paragraph below)
10.5 SDK: all archs work
10.6 SDK: same as g++-4.2 wth 10.6 SDK, just does not fail on compiling
(internal headers for ppc64 are not there so I don't understand this), but
rather on linking (ppc64 internal object files and system libraries do not
exist)

The only other thing to be aware of is that "g++" defaults to "g++-4.0" when
building on Tiger and Leopard, and to "g++-4.2" when building on Snow
Leopard.

So e.g. if you use g++-4.0 or g++-4.2 and compile for 10.5 SDK, you can get
4-way binaries running on 10.5 and later. If you use g++-4.0 and compile for
10.4 SDK, you can get 4-way binaries running on 10.4 or later, but be vary
that on Tiger, e.g. system's libz is 4-way, but system's libbz2 is only
2-way (32-bit), so you have to supply your own 4-way bz2 to iostreams (only
a few libraries on Tiger were 4-way). And if you do that with your own 4-way
static build of libbz2, you run into boost.build's library path issue that I
won't go into here (this post is already way longer than I intendet it to
be).

Sorry for the huge post, but I hope this attempt makes things a little bit
more understandable w.r.t. building for ppc64 (and even others) _on_ Snow
Leopard _for_ various target versions of Mac OS X.



Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk