Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Mac OS Runtime Architectures /
Chapter 3 - Programming for the CFM-Based Runtime Architecture


Weak Libraries and Symbols

During the build process, you can designate certain symbols or import libraries to be weak (usually with linker options), which indicates to the Code Fragment Manager that the symbol or library is not required for execution. For example, an application mooProg may designate the QuickTime shared library as a weak library. Then, while it can make use of QuickTime features if the library exists, it can still launch and execute normally without it. Similarly, a weak symbol is an imported symbol that does not have to be present at launch time. Weak symbols are sometimes called soft imports.

IMPORTANT
Although the Code Fragment Manager allows weak imports to remain unresolved at runtime, the application is still responsible for checking to see if the symbol or library was found and taking appropriate action. For example, if a library was not found, the application might display a message and set a flag to avoid accessing routines or data imported from that library.
If the Code Fragment Manager cannot find imported symbols designated as weak, all references to these imports are replaced with the value kUnresolvedSymbolAddress. Listing 3-6 shows how you can check for weak imports using this value.

Listing 3-6 Testing for weak imports

extern int dogCow (char *, ...);
...
if (dogCow == kUnresolvedSymbolAddress)
   DebugStr("\dogCow is not available.");
else
   printf("Hi Clarus\n");
The Code Fragment Manager checks for weak libraries before doing any preparation (resolving symbols and so on), and if the library exists, it is subsequently handled as a normal import library. For example, if an error occurs during preparation of the library, the Code Fragment Manager may abort the launch procedure, even though the library was designated as weak.

WARNING
You should not use the Gestalt function to check for weak imports or weak libraries.
If the Code Fragment Manager cannot find a weak library, you cannot subsequently resolve symbols imported from that library by calling Code Fragment Manager routines (GetSharedLibrary, for example).


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997