Actual build date in C++

901 Views Asked by At

I need to get build date of a module. I use __DATE__ macro. But it looks like if the file which contains this macro is not changed then it is not compiled and build date is left old and incorrect. How to make sure that build date updates? Maybe there is another way to get build date of the module?

1

There are 1 best solutions below

1
On

Everything you write is correct and works as it should:

When you use a build system, a file is only compiled when it has been changed, i.e. it is newer than the corresponding object file. So, you will always get the date when this particular file was compiled.

To get a new build date every time that any file of an application/library has changed, you have to make sure that the file that stores the build date is built every time too.
Normally a build system supports something like that, an option like "build always". Another (not recommended) way would be to delete the object file every time before you compile. Or (even worse), always make a clean build, i.e. delete everything and build everything every time.