How can I have the result of the git describe command embedded into my c++ binary so that I can access it at run time.
I know I can do something like this
g++ -DVERSION_NUMBER=2345
And then in my code I can do:
std::cout << VERSION_NUMBER << std::endl;
This is great but won’t work if the value of version number is a string such as the output of the git describe command.
So is there way to do such a thing?
Thanks.
If you use automake, then you can use something like the following. I have been using it for a long time now, and it works fine to achieve what you are asking for.
In
Makefile.am:In
echo_git_info.sh:The above will result in the the variable
GIT_SOURCE_DESCbeing defined in the filegit_info.h. Thus, in yourmain.cppyou can then: