Weak-linking [was: std::log10() problem]
Weak-linking [was: std::log10() problem]
- Subject: Weak-linking [was: std::log10() problem]
- From: Chris Espinosa <email@hidden>
- Date: Wed, 5 Apr 2006 10:37:29 -0700
On Apr 5, 2006, at 10:21 AM, Bill Monk wrote:
On 3/29/06, Chris Espinosa wrote:
Setting the Deployment Target does a lot of things: it triggers
weak linking in the frameworks that support weak linking and it
controls certain compiler and linker behavior for runtime
libraries. But as documented in the Cross-Development Programming
Guide, not all libraries (especially open-source ones) support the
weak-linking features that are triggered by the Deployment Target
setting, so you mave to manage weak-linking for these manually.
This makes sense, but here's something I don't understand.
The 10.4 API FSCreateStringFromHFSUniStr() is marked
AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER, which is #defined to be
WEAK_IMPORT_ATTRIBUTE when building for 10.4 or greater. So when
using the 10.4u SDK (gnu C/C++ 4.0) and a MACOSX_DEPLOYMENT_TARGET <
10.4 it should be weak linked, correct?
But as an example, consider the following code (similar to the
example at
http://developer.apple.com/documentation/DeveloperTools/Conceptual/cross_development/Using/chapter_3_section_5.html)
CFStringRef ConvertHFSUniStr255ToCFString( ConstHFSUniStr255Param
myHFSUniStrPtr )
{
CFStringRef myCFString = NULL;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 )
if ( NULL != FSCreateStringFromHFSUniStr )
{
myCFString = FSCreateStringFromHFSUniStr( kCFAllocatorDefault,
myHFSUniStrPtr );
}
else
#endif
{
myCFString = CFStringCreateWithCharacters( kCFAllocatorDefault,
myHFSUniStrPtr->unicode,
myHFSUniStrPtr->length );
}
return myCFString;
}
When compiled with 10.3 SDK and MACOSX_DEPLOYMENT_TARGET == 10.3,
the #if block compiles out and the app runs fine on 10.3.9.
When compiled with 10.4u SDK and MACOSX_DEPLOYMENT_TARGET == 10.3,
the #if block compiles in, and the app runs fine on 10.4.x. When run
on 10.3.9, however, it crashes, like this:
Link (dyld) error:
dyld: /TestApp.app/Contents/MacOS/TestApp Undefined symbols:
/TestApp.app/Contents/MacOS/TestApp undefined reference to
_FSCreateStringFromHFSUniStr expected to be defined in CoreServices
(CoreServices.framework is in the project, btw.)
It seems to me this should be weak-linked. What am I not
understanding here?
Yes, it should be weak-linked. From what you've shown above the code
is taking the right approach and you say you're building it the right
way. What I'd need to see to diagnose this is a) the linker
invocation line that's building the executable (to make sure the 10.4u
SDK is actually being used for linking), possibly b) the compiler
invocation line for the source file, and c) an nm output from the
executable to see how the import is being defined ( nm TestApp.app/
Contents/MacOS/TestApp | grep FSCreateStringFromHFSUniStr )
Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden