如何将版本信息嵌入共享库和二进制文件? [英] How to embed version information into shared library and binary?

查看:68
本文介绍了如何将版本信息嵌入共享库和二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,是否可以将版本信息嵌入到ELF二进制文件中?我想在编译时嵌入此信息,以便以后可以使用脚本将其提取.一种骇人听闻的方法是植入可以使用strings命令提取的内容.是否有更常规的方法,类似于Windows DLL的Visual Studio工厂版本信息(注意DLL属性中的版本"选项卡)?

On Linux, is there a way to embed version information into an ELF binary? I would like to embed this info at compile time so it can then be extract it using a script later. A hackish way would be to plant something that can be extracted using the strings command. Is there a more conventional method, similar to how Visual Studio plant version info for Windows DLLs (note version tab in DLL properties)?

推荐答案

使用cvs或subversion的一种方法是在源文件中格式化特殊的id字符串.然后在cvs或svn中添加一个预提交钩子,以在提交更改时使用文件的新版本更新该特殊变量.然后,在构建二进制文件时,可以使用ident提取该信息.例如:

One way to do it if using cvs or subversion is to have a special id string formatted specially in your source file. Then add a pre-commit hook to cvs or svn that updates that special variable with the new version of the file when a change is committed. Then, when the binary is built, you can use ident to extract that indformation. For example:

将类似这样的内容添加到您的cpp文件中:

Add something like this to your cpp file:

static char fileid[] = "$Id: fname.cc,v 1.124 2010/07/21 06:38:45 author Exp $";

在程序上运行ident(可以通过安装rcs找到)可以显示有关其中包含id字符串的文件的信息.

And running ident (which you can find by installing rcs) on the program should show the info about the files that have an id string in them.

ident program
program:
    $Id: fname.cc,v 1.124 2010/07/21 06:38:45 author Exp $

注意正如人们在评论中提到的那样,这种技术是过时的.让源代码管理系统自动更改源代码是很丑陋的,并且自从cvs成为唯一选择以来,源代码控制已得到改善,这意味着您可以找到一种更好的方法来实现相同的目标.

Note As people have mentioned in the comments this technique is archaic. Having the source control system automatically change your source code is ugly and the fact that source control has improved since the days when cvs was the only option means that you can find a better way to achieve the same goals.

这篇关于如何将版本信息嵌入共享库和二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆