I have an C++ program that runs on an embedded system. When the client encounters a problem he sends me a log file. And it would be great to see exactly when the binary was build in the log. So, currently I use this simple but very ineffective method:
…
const std::string APP_BUILD = "2012.01.17.18:28";
int main()
{
std::cout << "Was built: " << APP_BUILT << std::endl;
}
What I would like to do is to set APP_BUILD automatically during build. I know that Linux has /proc/version variable which can be read to determine build time. My reads
cat /proc/version
Linux version 2.6.38-13-generic (buildd@allspice) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) ) #53-Ubuntu SMP Mon Nov 28 19:33:45 UTC 2011
Can this be done? (I’m building my app in Linux).
It sounds like you’re looking for the
__DATE__and__TIME__macros. These standard macros are available in both C and C++.See, for example, the
gccmanual.