Note: this entry is a follow-up of this StackOverflow entry. It gathers tricks from Anatomic Wax, StackOverflow and my personal experience.

Installing Xcode 3.2.6

In order to install Xcode 3.2.6 correctly on Lion, you need to use a trick to fool the installer so it installs everything (via ):

  • Mount the Xcode 3.2.6 disk image
  • Open a terminal
  • Enter the commands:
export COMMAND_LINE_INSTALL=1
open "/Volumes/Xcode and iOS SDK/Xcode and iOS SDK.mpkg"

The open command will launch the installer app and allow you to install Xcode 3.2.6 on Lion with no package modifications.

You can choose not to install the MacOSX 10.4 SDK if you don't need it. Adapt the remaining steps if you don't.

When installing Xcode 3.2.6, choose a destination folder other than Developer. For the sake of this guide, the destination folder is Developer-3.2.

Installing Xcode 4.1

Installing Xcode 4.1 is done from the Mac AppStore. Once it is downloaded, click on the installer to start the installation.

Restoring 10.4/10.5 SDK Support

Open a terminal and run the following commands:

cd /Developer/SDKs
sudo ln -s /Developer-3.2/SDKs/MacOSX10.4u.sdk .
sudo ln -s /Developer-3.2/SDKs/MacOSX10.5.sdk . 

Restoring GCC 4.0/GCC 4.2 Support

A lot of links should be added so the compiler executables are found. Moreover, the platform suffix should also be changed from darwin10 to darwin11.

Run the following commands (there should be some errors, but you can safely ignore them):

cd /Developer/usr/bin
sudo ln -s /Developer-3.2/usr/bin/*4.0* .
sudo ln -s /Developer-3.2/usr/bin/*4.2* .
sudo ln -s powerpc-apple-darwin10-g++-4.0.1 powerpc-apple-darwin11-g++-4.0.1
sudo ln -s powerpc-apple-darwin10-gcc-4.0.1 powerpc-apple-darwin11-gcc-4.0.1
sudo ln -s powerpc-apple-darwin10-g++-4.2.1 powerpc-apple-darwin11-g++-4.2.1
sudo ln -s powerpc-apple-darwin10-gcc-4.2.1 powerpc-apple-darwin11-gcc-4.2.1

These commands are meant to make the platform match:

cd /usr/bin
sudo ln -s /Developer/usr/bin/powerpc-apple-darwin10-g++-4.2.1 powerpc-apple-darwin11-g++-4.2.1
sudo ln -s /Developer/usr/bin/powerpc-apple-darwin10-gcc-4.2.1 powerpc-apple-darwin11-gcc-4.2.1
cd /Developer/usr/libexec/gcc/
sudo ln -s /Developer-3.2/usr/libexec/gcc/powerpc-apple-darwin10 .
sudo ln -s powerpc-apple-darwin10 powerpc-apple-darwin11

These commands add the as support for PPC:

cd /Developer/usr/libexec/gcc/darwin/
sudo mkdir ppc
cd ppc
sudo ln -s /Developer-3.2/usr/bin/as .

These commands are needed if you plan to use Xcode in GUI mode:

cd /Developer/Library/Xcode/PrivatePlugIns
cd Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins
sudo ln -s "/Developer-3.2/Library/Xcode/Plug-ins/GCC 4.0.xcplugin" . 

These commands will restore the PPC support for GCC 4.2:

cd /Developer/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1
sudo mv as as.bak
sudo ln -s /Developer-3.2/usr/bin/as .

How to use

Once you have done all these command line works, you should be able to compile executable for PowerPC architecture on Lion. The typical command line looks like:

gcc-4.2 -arch ppc -isysroot /Developer/SDKs/MacOSX10.5.sdk main.c -o HelloWorld 

One more thing

Comments and feedback are welcome to correct/fix this entry.