Install GCC-4.2.1 (Apple build 5666.3) with Xcode 4.2

2011-10-30 17:36:48

As of Xcode 4.2 Apple have stopped bundling GCC with it, shipping only the (mostly) compatible llvm-gcc binary instead. The suggested fix is to install GCC using the osx-gcc-installer project. However, I wanted to build and install it from source, which apple provides at http://opensource.apple.com/.

You should already have installed Xcode 4.2 from the app store, then basically the following steps are to grab the tarball from the 4.1 developer tools source, unpack & compile it, then install it into the right places.

Instructions

# Grab and unpack the tarball
$ mkdir ~/tmp && cd ~/tmp
$ curl -O http://opensource.apple.com/tarballs/gcc/gcc-5666.3.tar.gz
$ tar zxf gcc-5666.3.tar.gz
$ cd gcc-5666.3

# Setup some stuff it requires
$ mkdir -p build/obj build/dst build/sym
# And then build it. You should go make a cup of tea or five whilst this runs.
$ gnumake install RC_OS=macos RC_ARCHS='i386 x86_64' TARGETS='i386 x86_64' \
  SRCROOT=`pwd` OBJROOT=`pwd`/build/obj DSTROOT=`pwd`/build/dst SYMROOT=`pwd`/build/sym

# And finally install it
$ sudo ditto build/dst /

And now you should have gcc-4.2 in your $PATH, available to build all the things that llvm-gcc fails to compile.

3 Comments on Install GCC-4.2.1 (Apple build 5666.3) with Xcode 4.2

  1. Would that overrides llvm-gcc or any components of the existing XCode 4.2.1 installed on my box?

  2. This was the best solution to the OSX Lion 10.7.3 llvm gcc compiler and RVM install problem. The "--with-gcc=clang" option still yielded a "yaml" compile issue. I left RVM installed. I took your suggestions above compiling the old non-llvm gcc compiler and then (re)installed Xcode 4.2.1 afterwards to ensure any of its stuff was not affected (a bit risky but heh). Then I installed the latest ruby (1.9.3-p0) with "rvm install 1.9.3". I did have "export CC=/usr/bin/gcc-4.2" in my "~/.rvmrc" file. It works.

    I hope your info above and mine helps others in the same situation I was in.

  3. I'm having some issues compiling on Lion:

    MLIBS=/opt/osdev-bootstrap/gcc-5666.3/obj/obj-i686-i686/./gcc/xgcc -B/opt/osdev-bootstrap/gcc-5666.3/obj/obj-i686-i686/./gcc/ -B/usr/bin/ -B/usr/lib/ -isystem /usr/include -isystem /usr/sys-include --print-multi-lib \ | sed -e 's/;.*$//' -e '/^\.$/d' ; \ for mlib in '' $MLIBS ; do \ strip -o libgcc_s.10.5.dylib_T${mlib} \ -s /opt/osdev-bootstrap/gcc-5666.3/obj/src/gcc/config/i386/darwin-libgcc.10.5.ver -c -u \ ./${mlib}/libgcc_s.1.dylib.tmp || exit 1 ; \ done MLIBS=/opt/osdev-bootstrap/gcc-5666.3/obj/obj-i686-i686/./gcc/xgcc -B/opt/osdev-bootstrap/gcc-5666.3/obj/obj-i686-i686/./gcc/ -B/usr/bin/ -B/usr/lib/ -isystem /usr/include -isystem /usr/sys-include --print-multi-lib \ | sed -e 's/;.*$//' -e '/^\.$/d' ; \ for mlib in '' $MLIBS ; do \ strip -o libgcc_s.10.4.dylib_T${mlib} \ -s /opt/osdev-bootstrap/gcc-5666.3/obj/src/gcc/config/i386/darwin-libgcc.10.4.ver -c -u \ ./${mlib}/libgcc_s.1.dylib.tmp || exit 1 ; \ done strip: object: /opt/osdev-bootstrap/gcc-5666.3/obj/obj-i686-i686/gcc/libgcc_s.1.dylib.tmp malformed object (unknown load command 12) strip: object: /opt/osdev-bootstrap/gcc-5666.3/obj/obj-i686-i686/gcc/libgcc_s.1.dylib.tmp malformed object (unknown load command 12) make[4]: *** [libgcc_s.10.5.dylib] Error 1 make[4]: *** Waiting for unfinished jobs.... make[4]: *** [libgcc_s.10.4.dylib] Error 1 rm cpp.pod gcov.pod gfdl.pod gcc.pod fsf-funding.pod gpl.pod make[3]: *** [all-stage1-gcc] Error 2 make[2]: *** [stage1-bubble] Error 2 make[1]: *** [all] Error 2 + exit 1 make: *** [install] Error 1

About You
Comment