Re: Getting link errors weak-linking against a framework fn
Re: Getting link errors weak-linking against a framework fn
- Subject: Re: Getting link errors weak-linking against a framework fn
- From: Chris Suter <email@hidden>
- Date: Thu, 10 Jun 2010 11:22:16 +1000
Hi Jens,
On Thu, Jun 10, 2010 at 2:04 AM, Jens Alfke <email@hidden> wrote:
> I’m having trouble weak-linking against a function in a system framework. It was added in 10.6 but I need my code to run on 10.5, so I check whether the function exists before calling it. But even though I weak-import the function, I get a link error.
>
> The function’s not declared in a header*, so I added my own declaration:
> extern OSStatus SecKeyCreateWithCSSMKey(const CSSM_KEY *key, SecKeyRef* keyRef) WEAK_IMPORT_ATTRIBUTE;
>
> I call it as follows:
> if (SecKeyCreateWithCSSMKey != NULL)
> SecKeyCreateWithCSSMKey(cssmKey,&keyRef);
>
> This works when I build against the 10.6 SDK, but building against 10.5 I get a link error:
>
> Undefined symbols:
> "_SecKeyCreateWithCSSMKey", referenced from:
> -[MYSymmetricKey _initWithCSSMKey:] in MYSymmetricKey.o
> _SecKeyCreateWithCSSMKey$non_lazy_ptr in MYSymmetricKey.o
> (maybe you meant: _SecKeyCreateWithCSSMKey$non_lazy_ptr)
> ld: symbol(s) not found
>
> So am I doing something wrong in my declaration, or is it simply impossible to weak-link with a function that’s newer than the SDK I build against?
I'm not an expert on this but it's my understanding that the linker
needs to know which library the function is in (it uses two-level
namespaces). This is to save time; it narrows the search that dyld
needs to make.
If you must use the 10.5 SDK, it looks like you could workaround the
problem by using the -U linker flag, which will cause dyld to search
all libraries for the symbol. You could also use -undefined
dynamic_lookup but that would affect all undefined symbols.
Really, it's best to use the 10.6 SDK.
I suppose you could also use 10.5 headers but link with the 10.6
libraries but that might have other side effects; I wouldn't recommend
this approach.
Kind regards,
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