Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6146197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:54:47+00:00 2026-05-23T18:54:47+00:00

How can I have the result of the git describe command embedded into my

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:54:48+00:00Added an answer on May 23, 2026 at 6:54 pm

    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:

    BUILT_SOURCES = git_info.h
    EXTRA_DIST = echo_git_info.sh win_config.h
    
    .
    .
    (main build recipes)
    .
    .
    
    git_info.h: $(HEADERS) $(SOURCES)
        echo_git_info.sh > git_info.h
    

    In echo_git_info.sh:

    #! /bin/sh
    
    function echo_git_info {
        if [[ $(which git 2> /dev/null) ]]
        then
            local STATUS
            STATUS=$(git status 2>/dev/null)
            if [[ -z $STATUS ]]
            then
                return
            fi
            echo "`git symbolic-ref HEAD 2> /dev/null | cut -b 12-`-`git log --pretty=format:\"%h\" -1`, "
            return
        fi
    }
    
    echo "// Auto-generated source/build information."
    echo "#define GIT_SOURCE_DESC \"`echo_git_info``date`\""
    

    The above will result in the the variable GIT_SOURCE_DESC being defined in the file git_info.h. Thus, in your main.cpp you can then:

    #include <iostream>
    #include "ginkgo_info.h"
    
    int main(int argc, char* argv[]) {
        std::cout << "Source is: " << $GIT_SOURCE_DESC << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

git log lists all commits, from all branches that have been merged into HEAD.
SQL Server procedure can return result sets. I have a table emp(emp__id, emp__name, ...)
I have 2 tables   1. Client   2. Operations Operations can result in:
I have a HQL query that can generate either an IList of results, or
I have a form that shows results from a database query, these results can
In my controller I have model operations that can return empty results. I've setup
Routines can have parameters, that's no news. You can define as many parameters as
I have a program that can have a lot of parameters (we have over
The mysql query result can have 1 or 2 rows with results. How would
I have a project tracked in git that has a master branch that becomes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.