Add version numbers and compile time to Linux programs, dynamic libraries, and static libraries

Source: Internet
Author: User
Tags printable characters strcmp

Adding version numbers and libraries to programs and libraries facilitates maintenance and upgrades.

Of course you can show in the file name, such as a program called Yun, the file name is written as yun_1.0.2, but this needs to be maintained each time, and not 100% to ensure that the current program is that version. Therefore, it is a good choice to show the version number inside the program.

-----------------------------------I was the procedure to split the line O------------------------------------

I. Enforceable procedures

The program internally defines the version macro, and then the main function prints the version number and compile time through the-v parameter, with the following code:

Note : __date__ (compile date), __time__ (compile time), refer to this article: pre-compiled macro definitions in C language.

#include <stdio.h> #include <string.h> #define VERSION "0.0.2"//here each release version to manually update the # define NAME "Yun" static void Show_info (char *argv[]) {if (0 = = strcmp ("-V", argv[1]) {printf ("%s version:%s (%s,%s) \ n", NAME, Version, __date__, __tim e__); return;} else if (0 = = strcmp ("-H", argv[1])) {printf ("Usage:%s [options]\n", NAME);p rintf ("options:\n");p rintf ("  void\trun %s\n ", name);p rintf ("  -v\tdisplay%s version information\n ", name);p rintf ("  -h\tdisplay help information\n "); return;} printf ("Usage:%s [-v | -h]\n ", NAME); return;} int main (int argc, char *argv[]) {if (2 = = argc) {show_info (argv); return 0;} printf ("Can You Feel me?\n"); return 0;}
Operating Effect:



Second, dynamic library, Static library

The library does not take the-V method because it is not an executable program.

We can add a version number string to the program, compile it into a library and use the strings command to view the code as follows:

/* Add.h */

#ifndef _add_h_#define _add_h_int ADD (int a, int b), #endif/* _add_h_ */

/* ADD.C */

#include "add.h"//here each release version to manually update const char *lib_info = "Libadd version:0.0.3 (2015-01-30, 08:30)"; int add (int a, int b) {R Eturn (A + b);}
compile and run results:
/* Static Library */


/ * Dynamic library * /

Description:

Strings command: Used to display printable characters in a file.

grep: Used to filter useless information because the custom library information contains "version", so only the lines containing "version" are displayed, otherwise there is too much information to find.

This method can also be used to add version information to an executable program .

Add version numbers and compile time to Linux programs, dynamic libraries, and static libraries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.