Framework Weak Linking Weirdness
Framework Weak Linking Weirdness
- Subject: Framework Weak Linking Weirdness
- From: David Aames <email@hidden>
- Date: Sat, 7 Jul 2007 12:18:37 +0100
Hi all,
I've been experimenting with weak linking a simple framework. To
strip out all the unnecessary parts, my framework only contains one C
function. The function signature is BOOL isFrameworkAvailable(void);
The purpose of this function is for the user of the framework to
determine whether the framework is available because if it is the
linker will assign it a valid address.
Now here comes the tricky part. Because I'm weakly linking the whole
framework I pass "-weak_framework MyFrameworkName" as Other Linker
Flags. This works as expected. If I run the application and the
framework is in place and I do a comparison like if
(isFrameworkAvailable == NULL) - it evaluates to false. Here's the
problem. If I delete the framework and re-run the app it still
doesn't equal NULL (here's the catch). But if I do something like:
void* ptr = isFrameworkAvailable;
if(ptr == NULL)
Now this comparison returns true as supposed. The question is why do
I have to go through that intermediate stage? Is this a bug or I'm
not doing things properly? I should note that if I print out
isFrameworkAvailable using NSLog it prints the value as 0x0 but
compared to 0x0 doesn't return true (I find this weird).
The solution which I found is to apply __attribute__((weak_import))
to the function signature. But I thought that if I link to the whole
framework weakly (-weak_framework) then the compiler adds this
declaration to all symbols.
On a side note, there is no way to apply the weak link attribute to a
ObjC class because really when it's compiled it's a call to
objC_msgSend. So all classes are kind of weakly linked by default, am
I right? Or not?
Many thanks,
David
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden