I have created a Command Line Utility C++ tool in XCode using Objective-C. I want the version number to be displayed in the Info of the created executable. So I have added the version number 1.0.0.0 in the Current Project Version field in the Build settings. However, when I build it, the version number does not get added to the created ‘Unix Executable File’.
Am I missing something?
Thanks for the help.
Unfortunately, Xcode will not embed the current project version into the executable by itself, as of version 3. I’m not sure if this has changed in Xcode 4.
I ran into this problem a couple of years ago. It turns out that:
Version numbers displayed in the Finder come from applications’ Info.plists. In the case of an application bundle, Info.plist is a file. In the case of an executable, it must be embedded in a __TEXT section. The format of the Info.plist is the same either way.
Xcode does not have one-click support for embedding Info.plists into executables, but it is possible.
Xcode doesn’t preprocess Info.plist files unless they’re going into an application bundle (e.g. to insert the value of CURRENT_PROJECT_VERSION).
I hacked up a solution, but it’s unpolished and probably doesn’t represent best practices.
First, I created a new, stock Info.plist file called Info_template.plist. I set
CFBundleVersionto${CURRENT_PROJECT_VERSION}, andCFBundleShortVersionStringto${CURRENT_MARKETING_VERSION}.Then, I added a Run Script phase called “Preprocess Info.plist” at the beginning of the build, using
/bin/shas the shell, with this script:I added
$(DERIVED_FILE_DIR)/Info.plistto its output files.Then, I opened the target’s build settings, and added this to Other Linker Flags:
This asks the linker to roll the generated Info.plist file into the executable.
Let me know how this works for you, or if I left anything out!