Using GCOV from Xcode

Q: How can I configure my Xcode project to work with the GCOV code coverage tool?

A: There are only a few steps to having your Xcode project instrumented to support the auto-generation of code coverage data supplied by GCOV. In order to keep your code coverage build separate from your Debug and Release builds, make a new build configuration called GCov_Build. To make a new build configuration from within Xcode:

  • Double-click your project name in the Groups & Files section

  • Select the Configurations tab

  • Select your Debug build configuration

  • Use the Duplicate button at the bottom of the window to copy your selection

  • Rename the copied configuration to GCov_Build

Figure 1: Project Info window with new GCov_Build build configuration

Figure 1, Project Info window with new GCov_Build build configuration

To configure the project targets to work with GCOV code coverage data:

  • Double-click your target and select the Build tab in the Info window that appears.

  • Select GCov_Build from the Configuration drop-down menu.

  • Add -lgcov to the Other Linker Flags build setting.

  • Check the boxes to activate the Instrument Program Flow and Generate Test Coverage Files build settings.

  • Select Customized Settings from the Collection drop-down menu to review your modified build settings.

Figure 2: Target Info window with settings customized to work with GCov

Figure 2, Target Info window with settings customized to work with GCov

For more information on GCov and using it with Mac OS X see the related Apple documentation.

Document Revision History

Date Notes
2007-02-23 First Version

Posted: 2007-02-23


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.