How to: Compile an application for 10.2 (or 10.3) using Xcode 2.1

Tonight, we finally released an update to iPodRip that allowed it to work again on 10.2 and 10.3 systems, as well as iTunes 4.9. Unfortunately, this release took WAY too long to get out, due to a number of reasons.

One of these is that both Mat and I failed to realise that when upgrading to Xcode 2.1 (and thus GCC 4), you can no longer compile for 10.2 and 10.3 systems earlier than 10.3.9. Bugger. We found this out the hard way, with tons and tons of emails coming in from angry users who could no longer run their beloved iPodRip! To put salt in the wound, iPodRip 3.8.1 still had problems reading iPods that had been used with iTunes 4.9, necessitating a re-write of the parser. Obviously, we didn't handle this as well as we should have, and we hope to have more reliable releases in the future.

Anyway, back to the topic of compiling for 10.2 and 10.3 using Xcode 2.1. We got a bunch of crash reports containing one of the following:

dyld: /Users/jflowers/Desktop/iPodRip.app/Contents/MacOS/iPodRip can't open library: /usr/lib/libgcc_s.1.dylib (No such file or directory, errno = 2)

dyld: /Volumes/iPodRip/iPodRip.app/Contents/MacOS/iPodRip can't open library: /usr/lib/libmx.A.dylib (No such file or directory, errno = 2)

The problem

We later found out (after a lot of searching and digging around) that GCC 4 uses a couple of shared libraries (libgcc_s and libmx) that are not available on earlier systems. Since GCC 4 is the default compiler when Xcode 2.1 is installed, this means that trying to compile an application without changing any settings will result in it not launching on systems earlier to 10.3.9. Ouch.

Tonight I found a page that mentions the incompatibility between GCC 4 and systems earlier than 10.3.9, but it doesn't contain any of the error messages (as above), which made it quite hard to find. Then again, maybe I'm just blind.

The solution

Right. So now that we know what the problem is, how do we solve it?

The first thing to do is ensure that you have the required SDKs (System Development Kits) installed. These can be installed from the Xcode Tools disk image. To compile for 10.2, install the 10.2.8 SDK. To compile for 10.3, install the 10.3.9 SDK.

Then open the project. Once it has opened, select the project itself (the little Xcode document icon, with the name of the project; in this case, "iPodRip"):

Xcode - Groups & Files screenshot

Then "Get Info" on the project by pressing the "Command" + "i" keys.

A window with general information about the project will appear. Towards the bottom of there is a popup button with the title "Cross-Develop Using Target SDK". Here, you need to select which system you would like to build against. Since iPodRip is designed to run on 10.2 and above, we select the 10.2.8 SDK:

Xcode - Project Information

This setting causes Xcode to compile against a certain set of libraries (located under /Developer/SDKs/), rather than the default one for your current system.

Following that, you need to change a couple of settings for the application (or framework) to run correctly on the target system. These options are available under the "Build" tab. Select "All Configurations" from the "Configuration" popup button, to ensure that the settings you change apply to all of the existing build styles (Debug, Release, etc).

The "Deployment Target" needs to be changed in order for the application to be linked correctly. This is available about 1/3 of the way down. Simply select the minimum version you are compiling for. In iPodRip's case, it's 10.2:

Xcode - Project Build Settings

The final step is to set the version of GCC that we will be compiling with. Unfortunately, there is no entry for this by default (a stupid oversight, in my opinion), so it has to be added manually. This involves pressing the "+" button just below the table, which will create a new entry. Type in "GCC_VERSION" (no quotes), hit tab to go to the next column, and then type in "3.3″ (no quotes).

Xcode - Project Build Settings

(The SDKROOT setting there is set by the selection of an SDK in the previous tab.)

If you clean the build and recompile, the project will build and link against the chosen SDK/system and with GCC 3.3. Yay!

Some notes

You may get the following warning when compiling:

"ld: warning NEXT_ROOT environment variable ignored because -syslibroot specified"

It appears to be harmless, so can probably be safely ignored.

If you are compiling against any frameworks, they will have to be recompiled against the proper SDKs/targets and with the correct version of GCC. With iPodRip, we use 3 frameworks, and the settings had to be applied to each.

That's about it! Hopefully someone out there finds this useful.

6 Responses to “How to: Compile an application for 10.2 (or 10.3) using Xcode 2.1”


  1. 1 Cameron

    This was very helpful, thank for posting. I do have one question, how is this handled with the universal binaries?

  2. 2 Jem

    No problems. I spent ages trying to figure out how to get this working, and there was basically no info on it, so I thought I could help others in the same position.

    I’m not sure about universal binaries. I haven’t had the time to get any of our software working on Intel, but I read you basically just need to compile it once for PPC (using the above method) and once for Intel (using GCC4), and you basically “smoosh” the two binaries together using a utility called “lipo” (included with the Dev Tools, I think). Whenever I get around to working on Universal Binaries, I’ll make sure to post some instructions up. :)

  3. 3 Tom Gray

    I very much apprciate the excellent article on how to compile XCode 2.1 down to 10.2 applications. I have only a few hundred customers of my little shareware application (a customized VT-100 terminal emulator used by fellow employees at my day job), but, many of them are still using 10.2 and 10.3.

    Thanks!

    Tom

  4. 4 Ryan

    I tried this with xcode 2.2.1 and I’m getting the following error when I go to compile:

    gcc-3.3 installation problem, cannot exec ‘cclobj’: No such file or directory
    Command /usr/bin/gcc-3.3 failed with exit code 1

    Any thoughts..?

    Thanks,

    -Ryan

  1. 1 Sci-Fi Hi-Fi » Blog Archive » PodWorks 2.8.5
  2. 2 Dev @ MacBlogs.org

Leave a Reply




Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Australia
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Australia