关于 ldconfig 的一个疑问

31 天前
 MartinWu

我用 cmake 来当作一个动态库的编译工具。动态库的命名由于一些原因,现在定为了 libhaha.so.1.123abc 中间版本号实际上就是取的 git commitid 。

现在出现个问题,现在 /usr/local/lib 下有

-rwxr-xr-x  1 root        root        196661112 5 月  29 11:20 libhaha.so.5.352efad6
-rwxr-xr-x  1 root        root        196661112 5 月  28 19:24 libhaha.so.5.145f528c
-rwxr-xr-x  1 root        root        196627472 5 月  28 16:18 libhaha.so.5.6910a61a
-rwxr-xr-x  1 root        root        196627088 5 月  28 14:20 libhaha.so.5.dd1296e1
-rwxr-xr-x  1 root        root        196616048 5 月  28 13:50 libhaha.so.5.74404bc4
-rwxr-xr-x  1 root        root        196615760 5 月  28 10:46 libhaha.so.5.78393c5a
-rwxr-xr-x  1 root        root        196407288 5 月  28 10:32 libhaha.so.5.fb9da2af
-rwxr-xr-x  1 root        root        196313496 5 月  27 20:06 libhaha.so.5.8e217c7c
-rwxr-xr-x  1 root        root        195853792 5 月  27 15:37 libhaha.so.5.7a6fe752

这么些版本,

而我在make install后,是这样的(我是这么设计的)

lrwxrwxrwx  1 root        root               29 5 月  29 12:42 libhaha.so.5 -> libframe_master.so.5.352efad6
lrwxrwxrwx  1 root        root               20 5 月  29 12:14 libhaha.so -> libframe_master.so.5
-rwxr-xr-x  1 root        root        196661112 5 月  29 11:20 libhaha.so.5.352efad6
-rwxr-xr-x  1 root        root        196661112 5 月  28 19:24 libhaha.so.5.145f528c
-rwxr-xr-x  1 root        root        196627472 5 月  28 16:18 libhaha.so.5.6910a61a
-rwxr-xr-x  1 root        root        196627088 5 月  28 14:20 libhaha.so.5.dd1296e1
-rwxr-xr-x  1 root        root        196616048 5 月  28 13:50 libhaha.so.5.74404bc4
-rwxr-xr-x  1 root        root        196615760 5 月  28 10:46 libhaha.so.5.78393c5a
-rwxr-xr-x  1 root        root        196407288 5 月  28 10:32 libhaha.so.5.fb9da2af
-rwxr-xr-x  1 root        root        196313496 5 月  27 20:06 libhaha.so.5.8e217c7c
-rwxr-xr-x  1 root        root        195853792 5 月  27 15:37 libhaha.so.5.7a6fe752

但是当我再ldconfig后,就变成了这样:

lrwxrwxrwx  1 root        root               29 5 月  29 12:43 libhaha.so.5 -> libframe_master.so.5.78393c5a
lrwxrwxrwx  1 root        root               20 5 月  29 12:14 libhaha.so -> libframe_master.so.5
-rwxr-xr-x  1 root        root        196661112 5 月  29 11:20 libhaha.so.5.352efad6
-rwxr-xr-x  1 root        root        196661112 5 月  28 19:24 libhaha.so.5.145f528c
-rwxr-xr-x  1 root        root        196627472 5 月  28 16:18 libhaha.so.5.6910a61a
-rwxr-xr-x  1 root        root        196627088 5 月  28 14:20 libhaha.so.5.dd1296e1
-rwxr-xr-x  1 root        root        196616048 5 月  28 13:50 libhaha.so.5.74404bc4
-rwxr-xr-x  1 root        root        196615760 5 月  28 10:46 libhaha.so.5.78393c5a
-rwxr-xr-x  1 root        root        196407288 5 月  28 10:32 libhaha.so.5.fb9da2af
-rwxr-xr-x  1 root        root        196313496 5 月  27 20:06 libhaha.so.5.8e217c7c
-rwxr-xr-x  1 root        root        195853792 5 月  27 15:37 libhaha.so.5.7a6fe752

我是始终没法理解这里 ldconfig 他的搜索顺序和规则。如果按照文件名上的版本号顺序,libhaha.so.5 不是应该指向 libhaha.so.5.8e217c7c 或者甚至 libhaha.so.5.fb9da2af 吗? 如果是按照文件的时间来排序,也是应该继续是 libhaha.so.5.352efad6 啊。

求解惑。

846 次点击
所在节点    Linux
4 条回复
vivisidea
31 天前
```
vivi@vivi:~/Documents$ sort --version-sort a.txt
libhaha.so.5.dd1296e1
libhaha.so.5.fb9da2af
libhaha.so.5.7a6fe752
libhaha.so.5.8e217c7c
libhaha.so.5.145f528c
libhaha.so.5.352efad6
libhaha.so.5.6910a61a
libhaha.so.5.74404bc4
libhaha.so.5.78393c5a
```

按照 version 排序规则,5.78393c5a 这个就是最新版本
vivisidea
31 天前
命名里面再加一个 build 时间戳呢
MartinWu
31 天前
@vivisidea #1 感谢!知道原因就好解决了。我这就处理下。
MartinWu
31 天前
@vivisidea #2 我最后改成 libhaha.so.5.ts.fb9da2af

ts 取的是对应 commit 的 commit time

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1045011

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX