GNU/Linux x86 hosted Cross Compiler for OS X 10.4 and later ----------------------------------------------------------- readme.txt - this file odcctools-20090808.tar.bz2 - odcctools 20090808 source gcc-5247.tar.gz - Apple gcc-5247 source odcctools-20090808-gcc-5247-bin.tar.bz2 - odcctools and gcc-5247 binaries Makefile - Makefile for building the binaries ChangeLog - ChangeLog 2009-12-01: updated odcctools to 20090808, which supports versions of OS X for i386 above 10.4. No 64-bit support. odcctools-20090808-gcc-5247-bin.tar.bz2 contains binaries for a GNU/Linux to OS X cross tool chain. Below are notes on installing and using the binaries, building them from source and notes on how to build other versions of gcc. odcctools Sources ----------------- Project page: http://docs.huihoo.com/darwin/opendarwin/projects/odcctools/ odcctools-20090808 release tarball: http://gcc.gnu.org/ml/gcc/2009-08/msg00142.html gcc Sources ----------- Project page: http://gcc.gnu.org/ Apple gcc-5247 release tarball: http://www.opensource.apple.com/tarballs/gcc/gcc-5247.tar.gz Good News, Bad News ------------------- For the target system's headers and libs you can use OSX 10.4 SDK available from Apple. That's the good news. The bad news is that Macs have a few other tools under /Developer/Tools that aren't included here such as SetFile and Rez. This might be a problem building some projects, though many projects either don't need them or can be modified to build without them. Get the SDK ----------- - Go to https://connect.apple.com - Join up if you're not a member - Log in - Go to 'Downloads' - Click 'Mac OS X' from the 'Downloads' sidebar - Download "Xcode Tools 2.2.1 (Disk Image)" If you open the disk image on a Mac the file you want will appear at: /Volumes/Xcode Tools/Packages/MacOSX10.4.Universal.pkg/Contents/Archive.pax.gz If you don't have a Mac: $ dmg2img xcode_2.2.1_8g1165_018213632.dmg # mount -t hfsplus -o ro,loop xcode_2.2.1_8g1165_018213632.img /mnt then the file is: /mnt/Packages/MacOSX10.4.Universal.pkg/Contents/Archive.pax.gz Install the Binaries -------------------- Untar odcctools-20090808-gcc-5247-bin.tar.bz2 in /, it'll create /opt/mac (or untar it elsewhere and move it). You have to rebuild it from the sources to install to a different prefix unfortunately. Then move the Developer/SDKs/MacOSX10.4u.sdk directory that was in the SDK Archive.pax.gz to /opt/mac/SDKs/MacOSX10.4u.sdk. Using the Binaries ------------------ There are two copies of each tool: $ ls /opt/mac/bin/ i686-apple-darwin8-ar powerpc-apple-darwin8-ar i686-apple-darwin8-as powerpc-apple-darwin8-as i686-apple-darwin8-checksyms powerpc-apple-darwin8-checksyms i686-apple-darwin8-cpp powerpc-apple-darwin8-cpp i686-apple-darwin8-g++ powerpc-apple-darwin8-g++ i686-apple-darwin8-g++-4.0.1 powerpc-apple-darwin8-g++-4.0.1 i686-apple-darwin8-gcc powerpc-apple-darwin8-gcc i686-apple-darwin8-gcc-4.0.1 powerpc-apple-darwin8-gcc-4.0.1 i686-apple-darwin8-gccbug powerpc-apple-darwin8-gccbug i686-apple-darwin8-gcov powerpc-apple-darwin8-gcov i686-apple-darwin8-indr powerpc-apple-darwin8-indr i686-apple-darwin8-install_name_tool powerpc-apple-darwin8-install_name_tool i686-apple-darwin8-ld powerpc-apple-darwin8-ld i686-apple-darwin8-ld_classic powerpc-apple-darwin8-ld_classic i686-apple-darwin8-libtool powerpc-apple-darwin8-libtool i686-apple-darwin8-lipo powerpc-apple-darwin8-lipo i686-apple-darwin8-nm powerpc-apple-darwin8-nm i686-apple-darwin8-nmedit powerpc-apple-darwin8-nmedit i686-apple-darwin8-otool powerpc-apple-darwin8-otool i686-apple-darwin8-pagestuff powerpc-apple-darwin8-pagestuff i686-apple-darwin8-ranlib powerpc-apple-darwin8-ranlib i686-apple-darwin8-redo_prebinding powerpc-apple-darwin8-redo_prebinding i686-apple-darwin8-seg_addr_table powerpc-apple-darwin8-seg_addr_table i686-apple-darwin8-segedit powerpc-apple-darwin8-segedit i686-apple-darwin8-seg_hack powerpc-apple-darwin8-seg_hack i686-apple-darwin8-size powerpc-apple-darwin8-size i686-apple-darwin8-strings powerpc-apple-darwin8-strings i686-apple-darwin8-strip powerpc-apple-darwin8-strip Each works with both the supported targets, Intel and PowerPC, using the options -arch i686 and/or -arch ppc (fat binaries work OK). The only difference between the two versions of each tool is the default target. Examples: $ PATH=$PATH:/opt/mac/bin $ powerpc-apple-darwin8-g++ -o hello hello.cpp $ file hello hello: Mach-O executable ppc $ i686-apple-darwin8-g++ -o hello hello.cpp $ file hello hello: Mach-O executable i386 $ powerpc-apple-darwin8-g++ -arch i386 -o hello hello.cpp $ file hello hello: Mach-O executable i386 $ powerpc-apple-darwin8-g++ -arch i386 -arch ppc -o hello hello.cpp $ file hello hello: Mach-O fat file with 2 architectures Example of configuring and building something: $ ./configure --host=i686-apple-darwin8 $ make You can also install other SDKs, and compile against them using the '-isysroot' option, e.g.: $ powerpc-apple-darwin8-g++ \ -isysroot /opt/mac/SDKs/MacOSX10.3.9.sdk -o hello hello.cpp Here is an example of how you might configure a project to use another SDK: $ ./configure --host=powerpc-apple-darwin8 \ CC="powerpc-apple-darwin8-gcc -isysroot /opt/mac/SDKs/MacOSX10.3.9.sdk" \ CXX="powerpc-apple-darwin8-g++ -isysroot /opt/mac/SDKs/MacOSX10.3.9.sdk" Rebuilding the Binaries with the Makefile ----------------------------------------- Put the Makefile and tarballs gcc-5247.tar.gz, odcctools-20090808.tar.bz2 and Archive.pax.gz (from the SDK, see "Get the SDK" above) in a temporary directory. Then, for example, to build and install everything in one go: # mkdir /opt/mac # chown myuser:mygroup /opt/mac $ make install If you want to separate the build from the install, for example if you want to build as a normal user and install as root, then you need to do five steps: # make install-sdk $ make odcctools # make install-odcctools $ make gcc # make install-gcc The default is to install to /opt/mac, if you want to use a different prefix then add 'PREFIX='. Another useful override is TARGETS, which lists target architectures to build compilers for. The default is: TARGETS="i686-apple-darwin8 powerpc-apple-darwin8". For example to only build the Intel compiler and install it to /usr/local, the last two steps would be: $ make gcc PREFIX=/usr/local TARGETS=i686-apple-darwin8 # make install-gcc PREFIX=/usr/local TARGETS=i686-apple-darwin8 Note that when the "-arch ppc" option is used with the i686 compiler (or vice versa) it works by invoking the other compiler, so you need to build both powerpc and i686 compilers to support both targets. Manually Building odcctools from Source --------------------------------------- Install the SDK (see "Get the SDK" above), e.g.: prefix=/opt/mac gunzip -c Archive.pax.gz | pax -r mkdir -p $prefix/SDKs mv Developer/SDKs/MacOSX10.4u.sdk $prefix/SDKs Build and install odcctools, e.g.: prefix=/opt/mac target=powerpc-apple-darwin8 tar xjf odcctools-20090808.tar.bz2 cd odcctools-20090808 ./configure --target=$target --prefix=$prefix \ --with-sysroot=$prefix/SDKs/MacOSX10.4u.sdk make make install $prefix is where you want to install the compiler on your GNU/Linux box and $target is either powerpc-apple-darwin8 or i686-apple-darwin8 for PowerPC or Intel Macs. Note that not all releases of odcctools will compile on GNU/Linux, and those that do may not compile on all architectures. Manually Building gcc from Source --------------------------------- For gcc you can build either from original FSF gcc sources or from Apple's modified sources. The Apple versions generally include some things that the equivalent FSF versions do not. The Apple specific command line options for example, and they will include code that had not been integrated upstream at the time of the release. The Apple sources aren't usually straight forward to build, but they should include a script 'build_gcc' which you can examine to see how Apple themselves did it. Recent FSF gcc sources, on the other hand, should be straight forward to build, so it makes sense to use those unless you have a particular reason for wanting the Apple ones. Programs compiled with gcc will by default depend on some support libs such as libgcc*.dylib, libstdc++*.dylib or libobjc*.dylib. However for most applications it should be possible to depend on the system libs already installed on the target Macs and you will not have to ship these libraries with your application. A big advantage of using the system libraries is that when building your applications you will be able to link to other third party and system libs that will have been built against the system versions of libgcc, libstdc++ and libobjc. For libgcc the default is to link against libgcc_s_10.4.dylib which is a stub for the version of libgcc_s.1.dylib installed on OSX 10.4, meaning that your applications will use the system libgcc. Note that this is the default with Apple gcc 4.0.1, but for the FSF version it only became the default with gcc 4.2.0. You can control the libgcc used using the -mmacosx-version-min compiler option, see gcc(1). For libobjc, which objective-C programs will depend on, the default is to use the headers and stub library in the SDK. So again your programs will use the system lib. See -fgnu-runtime and -fnext-runtime in gcc(1). Using the system libstdc++ isn't the default, but it can be done by configuring gcc with --with-gxx-include-dir to specify the system C++ headers and not building gcc's own libstdc++. The easiest way to avoid building libstdc++ is to delete its directory from the gcc sources before configuring. For this to work the version of gcc you are building must have the same C++ compiler ABI as the version the system libstdc++ was taken from. So far (i.e. up to 4.2.0 at least) gcc's C++ ABI has stayed the same since version 3.4.0. For example building FSF gcc 4.2.0: prefix=/opt/mac target=powerpc-apple-darwin8 targetprefix=/usr/local PATH=$PATH:$prefix/bin tar xjf gcc-4.2.0.tar.bz2 perl -pi -e "s|/usr/bin/libtool|$prefix/bin/$target-libtool|" gcc-4.2.0/gcc/config/darwin.h perl -pi -e "s|-Wl,-install_name,..slibdir.|-Wl,-install_name,/usr/lib|" gcc-4.2.0/gcc/config/t-slibgcc-darwin rm -r gcc-4.2.0/libstdc++-v3 mkdir build-gcc cd build-gcc/ ../gcc-4.2.0/configure --target=$target --prefix=$targetprefix \ --with-sysroot=$prefix/SDKs/MacOSX10.4u.sdk \ --with-gxx-include-dir=$prefix/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0 \ --enable-languages=c,c++,objc,obj-c++ \ --enable-version-specific-runtime-libs \ --with-as=$prefix/bin/$target-as \ --with-ld=$prefix/bin/$target-ld make Then as root: prefix=/opt/mac target=powerpc-apple-darwin8 PATH=$PATH:$prefix/bin make install prefix=$prefix cd $prefix/lib/gcc/$target/4.2.0 ln ../../../../SDKs/MacOSX10.4u.sdk/usr/lib/libstdc++.6.0.4.dylib . ln -s libstdc++.6.0.4.dylib libstdc++.6.dylib ln -s libstdc++.6.0.4.dylib libstdc++.dylib $targetprefix which is the location to which you will install any support libs on the target Macs and $prefix is the location the compiler will be installed to on the GNU/Linux machine. Alternatively you can make $targetprefix the same as $prefix as you probably won't ship any support libs, and if you do you can modify them with install_name_tool(1). More Information ----------------- Ronald S. Burkey site on cross compiling: http://www.sandroid.org/imcross/ The crossgcc mailing list: http://sources.redhat.com/ml/crossgcc/ Home of dmg2img: http://vu1tur.eu.org/tools/ ------------------- Mike Wetherell 2007-2009 mweth at users.sf.net