XCode3 - relationship between Library Search Paths and project Frameworks
Asked Answered
P

2

5

As a new MAc developer coming from VS I don't really 'get' what a framework is. If I add a framework to my project, does this automatically mean the headers should be found when I do #include <SomeFile.h>?

I seem to be finding in some cases I have to add header search paths as well. Does that mean the framework isn't working right?

Petulancy answered 3/5, 2012 at 21:59 Comment(0)
E
4

As defined by the Apple Conceptual Documentation:

A framework is a hierarchical directory that encapsulates shared resources, such as a dynamic shared library, nib files, image files, localized strings, header files, and reference documentation in a single package.

In other words, it is a compilation of resources that can be utilized by one or more applications, and it is not an application by itself.

Detailed by the Apple Conceptual Documentation:

You include framework header files in your code using the #include directive. If you are working in Objective-C, you may use the #import directive instead of the #include directive. The two directives have the same basic results. but the #import directive guarantees that the same header file is never included more than once. There are two ways for including framework headers:

#include <Framework_name/Header_filename.h>
#import <Framework_name/Header_filename.h>

In both cases, Framework_name is the name of the framework and Header_filename is the name of a header file in that framework or in one of its subframeworks.

When including framework header files, it is traditional to include only the master framework header file. The master header file is the header file whose name matches the name of the framework. For example, the Address Book framework has a master header file with the name AddressBook.h.

To include custom frameworks:

If your project links to frameworks that are not included in any of the standard locations, you must explicitly specify the location of that framework before Xcode can locate its header files. To specify the location of such a framework, add the directory containing the framework to the “Framework Search Paths” option of your Xcode project. Xcode passes this list of directories to the compiler and linker, which both use the list to search for the framework resources.

Emit answered 19/5, 2012 at 13:58 Comment(0)
C
3

If the framework is properly written, it contains the headers as well as the actual linkable (binary) file. The compiler (GCC formerly, LLVM-clang recently) recognizes framework paths and knows automatically where to search for framework headers. There are some corner cases though:

  1. If you don't add a framework, but really a traditional Unix library (libsqlite3.dylib, libxml2.dylib etc.) from /usr/lib. Then it may be the case that the library has a separate (unstandard) include path; this is common, for example, in the case of glib. You have to add /usr/include/glib-2.0 to your header search path in this case.
  2. The opposite case: when you encounter some of the "Umbrella" frameworks (for example, Core Audio is split up into small subframeworks, such as AudioToolbox.framework etc.), then that particular framework doesn't contain a linkable dynamic library, only headers.

I hope this helps.

Coed answered 19/5, 2012 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.