On Jul 19, 2005, at 10:56 AM, Dave Thorup wrote: Build Configurations seem to work well when I'm building a single library that doesn't link with anything else. In this scenario I can have a single target with three Build Configurations (Debug, Profiler and Release). But what can I do when I build an Application that needs to link with the Debug, Profiler and Release libraries depending on what kind of build I'm doing?
This should work without any special effort, IF your projects are set up correctly. I had a few people ask me about this at WWDC, and they all had made the mistake of adding the library to the link phase of the application by referencing a file from the file system (using the Project menu's "Add to Project..." item), rather than using a product reference. Xcode will automatically use the Configuration-specific name for a file if it was included via a reference to a project (or to another target within the same project).
Here's an explanation of the "right" way to do this in Xcode, as I understand it. I'll assume here that your application and your library are in different projects (else-wise, you can just skip the first step).
First, make a reference to your library project from the application project - Open the application project, and use the Project->Add to Project... menu item to add a reference to the library's xcode project file. You should be able to accept the default settings for adding a file, but make sure that "Copy items into destinations group's folder" is NOT checked.
Now that you have a reference from one project to the other, you should set up a dependency on the library target from the application target. Double-click the application target in the Groups & Files view, and use the "+" button on the "General" pane to set the application as being dependent on the library. (This isn't strictly necessary, but you'd normally want to have a dependency on the library, so if you change it, the application gets rebuilt, too.)
Final step - In the Groups & Files view, the referenced project is shown with a disclosure triangle. Click the triangle to show the products of the application project. Drag the library you want to link against to to the "Link Binary with Libraries" build phase of your application target.
When you change the active configuration, the reference to the library should automatically change names to match the configuration (though the UI might not update everywhere immediately - a known bug).
-Mark
|