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).
Display the /proc/version File The cat command displays the contents of the /proc/version file. This will output the Linux kernel version first, along with additional data about your operating system.
/proc/version has the linux kernel version (and some other stuff). /etc/redhat-release has the version/release of Redhat that you're using.
/proc/self is a real symbolic link to the /proc/ subdirectory of the process that is making the call. When you do ls /proc/$$ the shell expands it to ls /proc/pid-of-bash and that is what you see, the contents of the shell process. But when you do ls /proc/self you see the contents of the short lived ls process.
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 gcc
manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With