Interesting document - what does it mean?

Posted:
in macOS edited January 2014
<a href="http://developer.apple.com/techpubs/macosx/DeveloperTools/MachORuntime/MachORuntime.pdf"; target="_blank">http://developer.apple.com/techpubs/macosx/DeveloperTools/MachORuntime/MachORuntime.pdf</a>;



This doc has some interesting material about 10.2 - including 'weak binding'...



Anyone with a better understanding of this stuff able to translate?

Comments

  • Reply 1 of 1
    This is essentially the same as weak linking. If you're linking against a shared library or framework, and you specify that certain symbols (usually functions), or even the entire library is to be imported as weak; the runtime environment will allow the program to continue execution, even in the absence of those symbols.



    To give an example, let's say that you write a program that makes a certain call to one of Apple's frameworks (eg: HIToolbox) or a third party framework (eg: one of the Omni frameworks). Suppose that it is likely that your users will have different versions of the framework installed (so if the framework isn't in your application bundle, but in /System/Library/Frameworks/ or in ~/Library/Frameworks). You don't want to be using functions in these frameworks that aren't present in prior versions of the framework, without importing them as weak. Because if the user has the older version of the framework, your program may refuse to launch, or crash.



    So what you do, is you specify that you import your framework (or at least certain symbols) as weak. Then, prior to using a function that is imported as weak, you can check and see if the function pointer is NULL. If it is, then the function is not present in the framework and you shouldn't call it. This flexibility allows you to modify the behaviour of your program at runtime, to adapt to whatever versions of the framework the user has installed.
Sign In or Register to comment.