views:

378

answers:

3

I am trying to set up Xcode for a project which contains multiple executables and static libraries. I have created multiple targets and set up the linking and dependencies, and initially everything works great. The catch...

This is an existing project which already has Visual Studio and Makefile builds. Those builds put the libraries in a lib/Debug directory and the executables in bin/Debug. So in Xcode I changed the Build Products Path to "lib" and "bin" respectively (so we can use one set of documentation for all of the platforms). This puts the compiled targets in the right place, but completely breaks both the linking (Library not found) and the dependencies.

I can fix the linking by adding $(SRCROOT)/lib/Debug to the Library Search Paths for each executable (but it feels like Xcode should be able to figure this out on its own, which makes me think I'm doing something wrong).

But — I can't figure out how to get the dependencies working again. If I change a library source file, the library will rebuild but not the dependent executables. If I force a build of the executable Xcode returns success without doing anything; it thinks the target is up to date. If I clean the target and then rebuild it works.

So, any ideas here? Is Xcode being fundamentally stupid in this regard, or is it me (I'm leaning toward the latter)?

Update: I've posted a sample project to demonstrate the issue at http://share.industriousone.com/XcodeDepsIssue.zip. Build it once, then modify MyStaticLib.c and build it again. The executable will not relink (and it should). Many thanks for any help on this one.

+1  A: 

Xcode doesn't automatically set up dependencies based on use of build products; you have to set up explicit target dependencies yourself.

Project > Edit Target Settings, General tab, + button, add any targets that are prerequisites to building the selected target. That should get you going again.

cdespinosa
As I mentioned, I already set up the dependencies, and the project builds successfully as long as all targets are building to the same directory. The dependencies fail when I build different targets to different directories.
starkos
A: 

OK, it would help to have the text of the Linking... build line that's failing. But a couple of things:

1) You shouldn't be linking to anything in $(SRCROOT). That's your project sources. The two places to find things to link are $(SYMROOT) (the Build Products directory) or $(DSTROOT) (the Installed Products directory).

One thing you could do is to have a common Build Directory, then use 'xcodebuild install' action to install the products in the Installation Directory. The other is to use a Copy Files build phase to copy them after building, so you can link against them in $(SYMROOT) but still have them where your Windows compatriots expect them.

THere is probably a way to set up the per-target build products directories correctly, but I'd really have to see the project itself to figure it out.

cdespinosa
I've posted an example project at http://share.industriousone.com/XcodeDepsIssue.zip to demonstrate the issue. Many thanks for any insights.
starkos
In your App target, change the Library Search Paths for all configurations to $(inherited) $(SYMROOT)/../lib/$(CONFIGURATION) and that should work.
cdespinosa
Thanks for the answer, but no change. The app can finds the library and links just fine. The library rebuilds on changes, but the app never relinks.
starkos
A: 

I've researched this some more and the answer is no, Xcode 3.x doesn't track dependencies between targets that live in different directories. You can work around it by giving each library its own project, and adding each of those to a master project. Or you can keep all of your targets in one directory. Pick your poison.

starkos