Keep me going
give me coffee! Smoke 1 Smoke 2 Smoke 3

After a hard battle with weak linking of some Tiger CG calls (to run Q on Panther) we have finally a new nightly, that *runs* on Panther. I *know* it, since I have stripped two harddisk from an old server, set it up with new ones, inserted the old ones into an external HD enclosure, moved all the data form my Firewire HD so that I finally could setup a Panther system on my GFs Powerbook (txs btw ;)).

Let's elaborate a little further for the techie:

Weak linking offers the possibility to link against function calls that are not present/defined on the users system. This comes in handy when you like to use Tiger only functions, but you still want your binary to work on Panther. Basically you then code a Tiger path (makes use of the new function) and a Panther path (with replacement code). The binary checks at runtime whether the function call (symbol) is defined. If it is, you can make use oft it, obviously. Without weak linking, your program would normally abort right away, because the linker would not find the Tiger Symbol on Panther ("undefined reference to _xxx"). Now Apple introduced weak linking with 10.2.8. So You can use weak linking down to 10.2.8.

So where is the problem?

Well, first, if you build with "make", You need to define MACOSX_DEPLOYMENT_TARGET, else Your system will set it to 10.1, which does not support weak linking. Why? To weak link, the Function which you like to be weak linked needs the following attribute: "__attribute__((weak_import))". But the new functions, that Apple introduces with every release of OS X, are not weak linked by default. They are linked by rules defined in "AvailabiliyMacros.h". These macros set the attribute dynamically based on the *lowest* system the binary should work on. This is 10.1 by default. So to trigger these macros to use weak linking, MACOSX_DEPLOYMENT_TARGET needs to be set accordingly.

[edited, tx for pointing out phil]

Second, in early stages, Apple messed soething up with the documentation. Here is the sample code I googled up: (lesson learned: one should always use the recent files that come with xcode updates 🙂 ):

void MyAboutBox(void)
    if(HIAboutBox != NULL)
        // Lots of code to display an about box with earlier technology.

Problem was pointed out at cocoadev.

Grab it at http://www.kju-app.org.