getting compile-time date and time without macros

前端 未结 3 1811
粉色の甜心
粉色の甜心 2021-01-05 18:30

using c++

I compile my code on an automated schedule and need to use the time at which the code was compiled in the code itself. Currently I\'m just using the

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 18:54

    If you use the compile-time IN YOUR binaries, then you will have the binary change.

    There are several solutions, but I think the main point is that if you rebuild the binaries on a regular basis, it should really only be done if there are actually some changes (either to the build system or to the source code). So make it part of your build system to check if there are changes, and don't build anything if there isn't any changes. A simple way to do this is to check what the "latest version" in the version control system for the source code is. If the latest version is the same as the one used in the previous build, then nothing needs to be built. This will save you generating builds that are identical (apart from build time-stamp), and will resolve the issue of storgin __DATE__ and __TIME__ in the binary.

提交回复
热议问题