Storing version number in executables?

Storing version number in executables?

Post by Gildas Quinio » Tue, 21 Apr 1998 04:00:00



Hi!

Is there a way to store a version number and other such informations in
an executable like on Windoze?
I would like to check the build level of some pgm before launching them
and I would want to avoid something like:

    pgm_name -v

or so, to check them...

Thanks for your time...

Gildas Quiniou.

--
/-----------------------------*-----------------------------\
| Systmes & Technologies     | Tl:     +33 2 96438787     |
| Informatiques du Ponant     | Fax:     +33 2 96438788     |
| 27, rue Auguste Brizeux     | web:     http://www.stip.fr |
| 22200 Guingamp - France     | Minitel: 3615 STIP          |
\-----------------------------*-----------------------------/

 
 
 

Storing version number in executables?

Post by Russ Hor » Tue, 21 Apr 1998 04:00:00


A simple way would be to embed a 'what' string in your code.

Under 'c' you might do something like


When compiled you can run 'what filename'

and it would print

filename.c version 3.141592654

 
 
 

Storing version number in executables?

Post by David M. Co » Tue, 21 Apr 1998 04:00:00



>When compiled you can run 'what filename'

Didn't know that.

You can also use RCS.  Put a line like

static char *RCSinfo = "$Id$";

in your file, and it will get expanded to something like

static char *RCSinfo = "$Id: string.cpp,v 1.5 1998/04/20 14:14:28 dmcook
Exp dmcook $";

when you check the file in.  You can then use the ident command to get the
version of the executable.  I think there was a nice tutorial on RCS in the
Linux Gazette or Linux Journal, among other places.    

Dave Cook

 
 
 

Storing version number in executables?

Post by Bill Curri » Wed, 22 Apr 1998 04:00:00



> A simple way would be to embed a 'what' string in your code.

> Under 'c' you might do something like



But that will cause GCC to complain about unused static variables with
-Wall, and I use -Werror as well, so such files would never compile for
me.

Sure you can do hacky things like take the address of (in this case)
cVersion, but is there something better?  I know some compilers have a
#ident directive, but does GCC?

Bill
--
Leave others their otherness.

 
 
 

Storing version number in executables?

Post by Paul Flinder » Wed, 22 Apr 1998 04:00:00




> > Under 'c' you might do something like


> But that will cause GCC to complain about unused static variables with
> -Wall, and I use -Werror as well, so such files would never compile for
> me.


should be OK (at least gcc 2.7.2 is OK with it)

 
 
 

Storing version number in executables?

Post by Paul Kimo » Wed, 22 Apr 1998 04:00:00





>But that will cause GCC to complain about unused static variables with
>-Wall, and I use -Werror as well, so such files would never compile for
>me.

Under GCC, use

static char __attribute__ ((unused)) Version[]="blah blah version M_PI";

--
|||    "It was not granted you to complete the task, and           |||
|||     yet you may not give it up."      --Rabbi Tarfon           |||

 
 
 

Storing version number in executables?

Post by Bjorn Ree » Thu, 23 Apr 1998 04:00:00




> >When compiled you can run 'what filename'

> Didn't know that.

> You can also use RCS.  Put a line like

> static char *RCSinfo = "$Id$";

'what' is a SCCS related command, used to extract SCCS version

If you use RCS you would normally use the 'ident' command to
extract the RCS information. If you use RCS (or CVS) as repository,
but you also want to be able to use the SCCS 'what' command to
extract this information, then you can make your string something
like this

#if !(defined(lint) || defined(_lint_))

#endif

The #if/#endif is not necessary if you don't use lint (but you
should use it ;)

 
 
 

Storing version number in executables?

Post by Keith Nicho » Thu, 23 Apr 1998 04:00:00



> I would like to check the build level of some pgm before launching them

Uh, would RCS and "what" do the trick?

RCS can embed version information into the source which is then readable
from the exectuable using "what": it'll tell you the complete list of
sources and headers comprising the exectuable.  Might be more than you
want but it should get you started.

--
Keith Nichol                           | Address : Level 2, 175 Liverpool St,
Telstra Intelligent Network Platforms  |           Sydney 2000, Australia
                                       | Phone   : (+61) 2 9206 3429

 
 
 

Storing version number in executables?

Post by David Summe » Sat, 02 May 1998 04:00:00


Try out this little gizmo which I coded back about 1983 I think:

/*
 *
 * This program identifies both RCS and SCCS files.
 *
 */

static char *RcsId = "$Id$";

#include <stdio.h>

char line[256];

main( int argc, char **argv )
{
FILE *fp, *fopen();

if ( argc < 2 )
   {
   fprintf( stderr, "Usage: %s file [file ...]\n", argv[0] );
   exit( 0 );
   }

while ( --argc > 0 )
   {
   if ( (fp = fopen( *++argv, "r" ) ) == NULL )
      {
      fprintf( stderr,  "Can't open %s\n", *argv );
      continue;
      }
    else
      {
      printf( "%s:\n", *argv );
      scanfile( fp );
      fclose( fp );
      }
   }
exit(0);

Quote:}

int scanfile( FILE *file )
{
register int c;

while( (c = getc( file )) != EOF )
   {
   if ( (char) c == '$' )
      rcsmatch( file );

      sccsmatch( file );
   }

Quote:}

/* Group substring between two '$'s; then do pattern match. */
int rcsmatch( FILE *fp )
{
register int c;
register char *tp;

tp = line;
while( (c = getc(fp)) != '$' )
   {
   *tp++ = c;
   if ( c == EOF || c == '\n' || tp >= line + sizeof(line) - 2 )
      return 0;
   }
*tp++ = c;     /* append trailing '$' */
*tp   = '\0';
if ( strncmp( line, "Header", 6 ) == 0 ||
     strncmp( line, "Id", 2 ) == 0 )
   {
   printf( "\t$%s\n", line );
   return 1;
   }
 else
   {
   /* no match; put trailing '$' back into input */
   ungetc( c, fp );
   return 0;
   }

Quote:}


int sccsmatch( FILE *fp )
{
register int c;
register char *tp;

tp = line;
while( (c = getc(fp)) != '\n' && c != '\0' )
   {
   *tp++ = c;
   if ( c == EOF || c == '\n' || tp >= line + sizeof(line) - 2 )
      return 0;
   }
/* *tp++ = c;     /* append trailing '$' */
*tp   = '\0';
if ( strncmp( line, "(#)", 3 ) == 0 )
   {
   printf( "\t%s\n", line + 3 );
   return 1;
   }
 else
   {
   /* no match; put trailing character back into input */
   ungetc( c, fp );
   return 0;
   }

Quote:}

--
David Wayne Summers          "Linux: Because reboots are for upgrades!"

PGP Key fingerprint =  C0 E0 4F 50 DD A9 B6 2B  60 A1 31 7E D2 28 6D A8
 
 
 

1. How To Store The Date As A Number?

Hello,

I am a new user of UNIX. I am trying to store the date(Generated by date
command) as a number. I know that there are some conversion functions
in the C library but I don't know how to use them. What I want to do is
to do a subtraction as follow:

        <an integer>  -  <VAL(date string)>

The problem right now is that I don't know how to convert the date string
to an numerical value. Any help is appreciated. Please email me.

-------------------------------------------------------------------------------
Yuhang Au      

2. scsi problem on multia

3. Version tagging of libraries and executables, TIA

4. term 1.17: cannot connect to socket..

5. building static executables from dynamic executables on solaris

6. Free SCO newbie question

7. Building executables that run on old versions

8. Why Linux GCC is more robust then other development platforms?

9. Total store order and partial store order

10. AIX C 3.1.4 compiler generated executables not portable to older AIX Versions

11. version of executables

12. How to version-stamp executables?

13. How to partition a disk to store two OS versions?