How to store a version number in a static library?

后端 未结 5 1660
一整个雨季
一整个雨季 2021-01-02 16:47

How can I store a version number in a static library (file.a) and later check for its version in Linux?

P.S. I need possibility to check version of file any time wit

5条回答
  •  生来不讨喜
    2021-01-02 17:02

    If you are using gcc, you can use the #ident directive

    #ident "Foo Version 1.2.3.4"
    void foo(void){ /* foo code here */ }
    

    To get the version just use one of the following:

    strings -a foo.o | grep "Foo Version"
    strings -a foo.a | grep "Foo Version"
    strings -a foo.so | grep "Foo Version"
    

    This will allow you to compile the version into the library with the capability of later stripping it out using strip -R .comment your_file or completely omit it by passing -fno-ident (This will also omit the compiler version comments from the compiled objects)

提交回复
热议问题