Thread: How to view program version number ?

  1. #1
    Registered User
    Join Date
    Apr 2021
    Posts
    19

    How to view program version number ?

    I wrote a C program for both Linux and Windows.
    I use Git to store versions of the code.
    Is there a way to have the program version displayed when I start it ? Can you tell me how to write these lines of code ?

    To know the current version of the written code, from bash just write:
    Code:
    git describe --abbrev = 4 --always --tags

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    In your makefile (or some pre-build step), do
    Code:
    echo 'const char *version="'$(git describe --abbrev = 4 --always --tags)'";"' > version_info.c
    Then compile and link with that file, with an 'extern const char *version;' and 'printf("Version=%s\n", version);'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2021
    Posts
    19
    Thank Salem.
    Correct
    Code:
    echo 'const char *version = "'$(shell git describe --abbrev=4 --always --tags)'";' > version_info.c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program to view 10 lines of file.
    By willowwolf in forum C Programming
    Replies: 2
    Last Post: 04-24-2018, 04:17 PM
  2. Version number stored in .exe!
    By Marreoragarn in forum C Programming
    Replies: 6
    Last Post: 02-24-2015, 11:25 AM
  3. Linux Version number and hardwares list
    By arunarora in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2009, 03:17 AM
  4. Operating System version number
    By rehan in forum Windows Programming
    Replies: 5
    Last Post: 08-29-2008, 11:39 AM
  5. Get current program version
    By _izua_ in forum C++ Programming
    Replies: 8
    Last Post: 08-15-2007, 12:32 PM

Tags for this Thread