Weak Linking To Spotlight

Q: I'm writing a program that uses the Spotlight APIs (from the Metadata framework) if they are available. I set MACOSX_DEPLOYMENT_TARGET to 10.3 and then use weak linking to check for the availability of these APIs. However, when I run my program on Mac OS X 10.3.x, it won't launch, complaining that the MDQuerySetSearchScope symbol is not available. What gives?

A: Many of the declarations in the Metadata framework are suffixed by the MD_AVAIL macro, which declares the symbol to be imported weak if you're targetting a pre-10.4 system. However, due to a bug (r. 4097766), some of the declarations are missing that macro.

You can workaround this problem by simply editing the headers in the Metadata framework to include this macro. To make this even easier, we've supplied some fixed headers at the end of this document. You can install these by copying them to /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Headers/ (or /Developer/SDKs/MacOSX10.4.0.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Headers/ if you're using Xcode's SDK support).

Apple will provide a proper solution in the next release of the Metadata framework headers.

For more information about weak linking and binary compatibility, see Technical Note TN2064, 'Ensuring Backwards Binary Compatibility - Weak Linking and Availability Macros on Mac OS X'.

Downloadables

Document Revision History

Date Notes
2005-06-03 Describes a problem with weak linking to Spotlight (the Metadata framework), and its solution.

Posted: 2005-06-03


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.