有人可以解释一下Linux库命名吗? [英] Can someone explain about Linux library naming?

查看:97
本文介绍了有人可以解释一下Linux库命名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上创建库时,我使用以下方法:

When I create a library on Linux, I use this method:


  1. Build:libhelloworld.so.1.0.0

  2. 链接:libhelloworld.so.1.0.0 libhelloworld.so

  3. 链接:libhelloworld.so.1.0.0 libhelloworld.so.1

版本控制是这样的,如果你改变public面对的方法,你可以建立libhelloworld.so.2.0.0例如(并离开1.0.0

The versioning is so that if you change the public facing methods, you can build to libhelloworld.so.2.0.0 for example (and leave 1.0.0 where it is), so that applications using the old library won't break.

但是,命名它的意义是什么1.0.0 - 为什么不使用libhelloworld .so和libhelloworld.so.1?

However, what's the point in naming it 1.0.0 - why not just stick with libhelloworld.so and libhelloworld.so.1?

,最好的做法是使用1.0.0命名库, 1?

Also, is it best practice to name your library using 1.0.0 for example, or just 1?

g++ ... -Wl,-soname,libhelloworld.1

或:

g++ ... -Wl,-soname,libhelloworld.1.0.0


推荐答案

我给同事发送了关于这个问题的旧电子邮件:

From an old email I sent to a colleague about this question:

让我们以libxml为例。首先,共享
对象存储在/ usr / lib中,其中一系列符号链接表示
库的版本availiable:

Let's look at libxml as an example. First of all, shared objects are stored in /usr/lib with a series of symlinks to represent the version of the library availiable:

lrwxrwxrwx 1 root root     16 Apr  4  2002 libxml.so -> libxml.so.1.8.14
lrwxrwxrwx 1 root root     16 Apr  4  2002 libxml.so.1 -> libxml.so.1.8.14
-rwxr-xr-x 1 root root 498438 Aug 13  2001 libxml.so.1.8.14

如果我是libxml的作者,我出来一个新版本,libxml
2.0.0打破了界面兼容性与以前的版本,I
请将其安装为libxml.so.2和libxml.so.2.0.0。注意它是
,直到应用程序员负责他链接
。如果我真的肛门,我可以直接链接到libxml.so.1.8.14和
任何其他版本将导致我的程序不运行。或者我可以
链接到libxml.so.1,并希望libxml开发人员不
打破符号兼容性在我的1.X版本。或者如果你不
care和鲁莽,只是链接到libxml.so并获得任何版本
有。有时,当足够的人这样做,图书馆作者
必须有创意与更高版本。因此,libxml2:

If I'm the author of libxml and I come out with a new version, libxml 2.0.0 that breaks interface compatiblity with the previous version, I can install it as libxml.so.2, and libxml.so.2.0.0. Note that it is up to the application programmer to be responsible about what he links to. If I'm really anal, I can link directly to libxml.so.1.8.14 and any other version will result in my program not running. Or I can link against libxml.so.1 and hope that the libxml developer doesn't break symbol compatibility on me in the 1.X version. Or if you don't care and are reckless, just link to libxml.so and get whatever version there is. Sometimes, when enough people do this, the library author has to get creative with later versions. Hence, libxml2:

lrwxrwxrwx 1 root root     17 Apr  4  2002 libxml2.so.2 -> libxml2.so.2.4.10
-rwxr-xr-x 1 root root 692727 Nov 13  2001 libxml2.so.2.4.10

注意,在这一个没有libxml2.so。看起来像开发人员
厌倦了不负责任的应用程序开发人员。

Note that there's no libxml2.so in this one. Looks like the developer got fed up with irresponsible application developers.

这篇关于有人可以解释一下Linux库命名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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