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

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

问题描述

在Linux上,是否有将版本信息嵌入到ELF二进制文件的方法?我想在编译时嵌入此信息,以便稍后使用脚本将其解压缩。一种骇人听闻的方式是种植一些可以使用字符串命令提取的东西。是否有更传统的方法,类似于Visual Studio植物版本信息的Windows DLL(注意DLL属性中的版本选项卡)?

解决方案

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



在你的cpp文件中添加如下内容:

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

在程序上运行ident(可以通过安装rcs找到)应该显示关于

  ident程序
程序:
$ Id:fname。 cc,v 1.124 2010/07/21 06:38:45作者Exp $

注意正如人们在评论中提到的那样,这种技术是陈旧的。让源代码管理系统自动更改您的源代码是很丑陋的,源代码控制自CVS成为唯一选择的日子以来得到了改进,这意味着您可以找到更好的方法来实现相同的目标。

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)?

解决方案

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:

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 $";

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 $

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.

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

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