Re: Best Practice or The Way
Re: Best Practice or The Way
- Subject: Re: Best Practice or The Way
- From: Ken Thomases <email@hidden>
- Date: Sat, 16 Jan 2010 09:42:48 -0600
To expand on what Seth wrote:
Are your static libraries built with Xcode? The most natural fit with Xcode is to add a target to your project which builds the static library. In a project with Debug and Release configurations, those configurations will also impact the new target, so the library can be built differently.
You'd then establish a dependency from your application or main program target on the library target. That ensures that the library will get built as necessary prior to the app or main program being built.
Finally, you'd add the product of the static library target, found in the Products smart group, to the Link Binary With Libraries build phase of the app or main program target. That arranges for the app or main program to be linked to the library.
Xcode will take care of linking against the build from the matching configuration. So, a Debug build of your app will link against the Debug build of the library, and the Release build of the app will build against the Release build of the library.
If the libraries are used for multiple projects, then you might create a separate project for them (or a project for each static library, perhaps). You then add the project(s) for the libraries to the project for the app. You do that in the same way as you add any other file to a project (e.g. drag-and-drop, or Project > Add to Project). After that, the setup follows what I described above. You set up the dependency between the main target and the library targets and add the library products to the link phase of the main target.
In this case, since there are multiple projects, the configurations don't _necessarily_ match. If you just use Xcode's templates then they will by default. If they don't match, then Xcode will try to use the same-named configuration when building dependency targets, but will fall back to the default configuration if there is no same-named configuration in the dependency project.
On Jan 11, 2010, at 7:57 PM, David Blanton wrote:
> I add my libs to the frameworks folder in Xcode app project and they get linked ... is this the correct process?
The "Frameworks" folder is just a group. You can add any file you like to an Xcode project and put it anywhere you like in the group hierarchy. However, that, in and of itself, has no effect on building. Files can be in the project but completely "inert". Also, groups are purely for your organizational purposes, although there are some conventions suggested by Xcode's templates.
So, in short, merely putting something in the Frameworks folder has no special significance and doesn't change how anything is built.
To affect builds, you have to add files to targets -- actually, build phases of targets. What you may have done is added the libraries to the Frameworks folder _and_ added them to the target in one fell swoop. The sheet that Xcode presents when you add something to a project offers the chance to add it to targets at the same time. If you opted to add the libraries to a target, then that explains why they would then be linked into that target's product. (You can manually put files into specific build phases, but if you merely tell Xcode to add one to a target, it usually figures out the proper phase it goes into based on its type. In the case of a library, that would be the Link Binary With Libraries phase.)
> Then when changing to debug / release I and to see these lib change to debug / relase but they don't so I have been deleting the one and adding the other. Stupid but I know no other way.
This shouldn't be necessary. If your static libraries are not built by Xcode and you can't use the techniques described above, then you may be able to use an undocumented build setting. Add both the debug and release libraries to the main target. Then, go into the target's build settings and add a user-defined build setting with the name EXCLUDED_SOURCE_FILE_NAMES to all configurations. For the Release configuration, set its value to the name of the debug library (it's the opposite because we're specifying exclusions). Likewise, for the Debug configuration, exclude the release library.
Regards,
Ken
_______________________________________________
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