Re: Availability Macros question
Re: Availability Macros question
- Subject: Re: Availability Macros question
- From: Matthew Formica <email@hidden>
- Date: Tue, 10 Sep 2002 15:44:57 -0700
On 9/10/02 12:40 PM, "Bill Cheeseman" <email@hidden> wrote:
>
Can someone explain the AvailabilityMacros release note to me?
>
>
I think I understand the use of the upper-bound compiler flag, but the
>
lower-bound flag puzzles me.
>
>
The release note (supplemented by comments in the header file) says that
>
setting the lower-bound compiler flag for an application that will be run
>
only on, say, Mac OS X 10.1 or newer, will cause some system functions that
>
are available on newer systems but not older systems to be weak linked. So
>
what? What benefit does this confer on the application, or whatever?
The benefit is that if a symbol is weak-linked and it isn't present at
runtime on a given OS version, the application will still run (and it'll be
up to your code to notice that a given function pointer points to NULL and
can't be executed). If everything is strongly linked, then if your app that
uses NSNiftyNew10.2OnlyRoutine() is double-clicked on a 10.1.x system, it
will fail to launch, with dyld (the dynamic loader) complaining that it
can't find the _NSNiftyNew10.2OnlyRoutine symbol in AppKit.framework (or
wherever the symbol sits on a 10.2 system). If that symbol were
weak-linked, then theoretically this would work and your app would still run
on 10.1.x.
However, there is a practical problem to be considered here: weak linking as
a feature was just added to 10.2, and does not exist in 10.1. So binaries
that weak link against symbols will not run at all on 10.1, because dyld
will not know what to do with the weak references. Thus, weak linking is
really a feature for apps going forwards, not for apps needing 10.1.x
compatibility.
To help sort out this confusion (or perhaps add to it), ld (the linker) pays
attention to a MACOSX_DEPLOYMENT_TARGET environment variable (see the ld man
page) that determines whether it will bother trying to setup any weak
references in your application. The two values that the
MACOSX_DEPLOYMENT_TARGET variable can have are 10.1 and 10.2, with 10.1
being the default. Thus, in spite of whatever the release notes and the
header say, no weak symbols will be generated no matter what your
MAC_OS_X_VERSION_MIN_REQUIRED setting is, unless you also set the
MACOSX_DEPLOYMENT_TARGET environment variable to 10.2 (which can be done in
your Target pane in PB by going to the Expert view and adding a new
MACOSX_DEPLOYMENT_TARGET build setting).
All this will end up in a technote, hopefully soon, since various people
have been asking for an explanation of this info.
>
>
Also, does setting this compiler flag cause the system to refuse to run the
>
application on an older system, or raise an alert? Or does it only control
>
compilation branches?
It only controls compilation. dyld will handle failing to launch your app
all by itself without any extra help. :-)
>
>
A similar question was asked two weeks ago but never answered.
>
>
--
>
>
Bill Cheeseman - email@hidden
>
Quechee Software, Quechee, Vermont, USA
>
http://www.quecheesoftware.com
--
Matthew Formica
DTS Engineer - Developer Tools and Cocoa
Apple Computer, Inc.
email@hidden
Mac OS X Development Tools:
http://developer.apple.com/tools/
Project Builder on the web:
http://developer.apple.com/tools/projectbuilder/
Project Builder FAQ:
http://developer.apple.com/tools/projectbuilder/faq.html
Cocoa docs on the web:
http://developer.apple.com/techpubs/macosx/Cocoa/CocoaTopics.html
Cocoa sample code:
http://developer.apple.com/samplecode/Sample_Code/Cocoa.htm
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.