Re: Question on constructing an iOS static library for sharing
Re: Question on constructing an iOS static library for sharing
- Subject: Re: Question on constructing an iOS static library for sharing
- From: Wim Lewis <email@hidden>
- Date: Tue, 26 Mar 2013 14:06:40 -0700
On 26 Mar 2013, at 1:40 PM, David Hoerl wrote:
> I read here recently that it's considered proper to not directly link to system frameworks in a static library. I'm trying to figure out how to do that.
I'm not sure what advice you're referring to, but I'd guess that you're already doing the right thing because it's the default behavior of the tools.
A static library is basically just an archive of a bunch of .o files (and an index). Normally, a .o file doesn't refer to libraries --- they have unresolved symbol references, and when you link them into an app or a framework or dylib, the linker resolves those against the libraries you specify. But before that link stage, the symbols don't refer to any specific library.
> There is a popup in the Build Phases "Link Binary with Libraries" for each library/framework that offers "optional" and "required". Hmm, "optional" looks good, but trying to find information on this setting has not been fruitful.
>
> I did find an article that said the way to do this is not link at all (remove all the libraries), and set a linker flag "-weak_framework" (or "-weak_library") with a parameter for each framework/library the static library needs.
Don't quote me on this, but I believe the Xcode setting "optional" corresponds to the linker option "weak_{framework,library}" and the meaning in both cases is that if the library is not found at run time, the OS will allow your program to start but will set all the functions and variables that would have come from that library to NULL. (Normally a missing library means your program can't even start.) You should only use weak linking if your program tests for the existence of the things it uses from that library at runtime, and can do something useful if they're missing --- see [1].
The documentation for the linker ("man ld") has a very brief description of that.
(Note that there are two completely different things referred to as "weak" symbols in libraries; this is one of them.)
[1] https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
Wim.
_______________________________________________
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