Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I implement functionality similar to linux /proc/version in a c++ program?

Tags:

c++

linux

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).

like image 465
Nick Borodulin Avatar asked Jan 17 '12 14:01

Nick Borodulin


People also ask

Which of the command given in options will list proc version in output?

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.

What is proc version?

/proc/version has the linux kernel version (and some other stuff). /etc/redhat-release has the version/release of Redhat that you're using.

What is self proc?

/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.


1 Answers

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.

like image 98
NPE Avatar answered Oct 19 '22 05:10

NPE