Large projects usually already have some type of mechanism for build numbering, because keeping track of which build is the latest can be very important information. However, even small hobby projects can benefit from a self-maintaining build numbering system.

BuildNumber is a utility to add auto-incrementing build numbers to C and C++ projects. BuildNumber will create and maintain a single header file called buildnumber.h for your project which you can #include to access the current build number. BuildNumber is written in pure C for maximum portability, but the binary can also be used with C++ projects, and the source should compile with almost any C/C++ compiler.

The entire contents of a sample buildnumber.h are displayed below:

  /* Generated by BuildNumber version 0.8 */
  #ifndef BUILD_NUMBER_H_
  #define BUILD_NUMBER_H_
  #define BUILDNUMBER 53
  #define BUILDNUMBER_STR "53"
  #endif /* BUILD_NUMBER_H_ */

Every time you rebuild your project, BuildNumber will automatically update this file for you: set it up once, and it just works. You can compile individual files (to confirm syntax, etc) without incrementing the build number, because it only updates when you actually build or make your project.