Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4: How to Add Static Library Target Dependency to Project

I know, this has been asked a few times, but mostly for Xcode 3.x. For the iPad, I have two projects both living in a common workspace

  • Foo, a view-based application and
  • Foolib, a static Cocoa-Touch library

the former depending on the latter. I seem unable to work out how to add that dependency. It's not well explained in the documentation, so I tried the following:

  1. Click on the Foo project in the Navigation Area on the left,
  2. Select Build Phases up the top and expand the Target Dependencies section
  3. Click the plus button, but the resulting list is empty.

I have also tried to drag/drop the .a file into that section, with little success. Also, the documentation states

If the build product of one project in a workspace is dependent on the build product of another project in the workspace (for example, if one project builds a library used by the other project), Xcode discovers such implicit dependencies and builds in the correct sequence.

I wonder how Xcode discovers those dependencies. Is Apple saying I don't have to add this target dependency at all? But then how would Xcode discover that one is using the other?

Last but not least, I will need to get the .h files from Foolib across to Foo somehow. What is the recommended way of doing that? Obviously, I don't want to just copy them. With frameworks the header files come included, but what do people generally do when working with static libraries that they themselves develop in parallel.

A nudge in the right direction would be much appreciated. Thank you.

like image 578
McKrassy Avatar asked May 13 '11 02:05

McKrassy


People also ask

Does static library include dependencies?

If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.

How do I create a static library in XCode?

Open XCode and start a new project. Under iOS, select Library and “Cocoa Touch Static Library” say it as "staticlibrary". This will create a nice new project for us that builds a . a file.

What is target dependencies XCode?

A dependency is another target that must be built before the current target can be. For example, if you have an app target and a framework target, the app target can have the framework target as a dependency, to ensure that the framework is built first. That is, the app target "depends" on the framework.


1 Answers

In general Xcode 4 seems to discover the dependencies automatically as the Edit Scheme sheet implies. Other developers have mentioned that the dependencies are not automatically discovered and require explicitly listing them:

So, Edit Scheme -> Build -> add targets from your workspace.

As far as the static library header files go, Xcode 4 seems to have a problem, at least with code completion and syntax highlighting. The only way I can get either to work properly with classes in static libraries to to drag a copy of the header files in question to a location into a group folder in the main project. Note that you should uncheck Add to Target... That takes care of the syntax highlighting and code completion. The rest should be handled by giving it the proper header search path. That would be User Header Search Paths = $(BUILT_PRODUCTS_DIR) - depending on how you set up your locations preferences.

See: this link

like image 140
FluffulousChimp Avatar answered Dec 28 '22 23:12

FluffulousChimp