关于 ldconfig 的一个疑问 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
MartinWu
0D
V2EX    Linux

关于 ldconfig 的一个疑问

  •  
  •   MartinWu
    Martwu 2024-05-29 13:07:35 +08:00 1354 次点击
    这是一个创建于 574 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我用 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 啊。

    求解惑。

    4 条回复    2024-05-29 14:58:22 +08:00
        1
    vivisidea  
       2024-05-29 13:42:28 +08:00
    ```
    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
    vivisidea
        2
    vivisidea  
       2024-05-29 13:45:03 +08:00
    命名里面再加一个 build 时间戳呢
    MartinWu
        3
    MartinWu  
    OP
       2024-05-29 13:48:21 +08:00
    @vivisidea #1 感谢!知道原因就好解决了。我这就处理下。
    MartinWu
        4
    MartinWu  
    OP
       2024-05-29 14:58:22 +08:00
    @vivisidea #2 我最后改成 libhaha.so.5.ts.fb9da2af

    ts 取的是对应 commit 的 commit time
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1243 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 17:29 PVG 01:29 LAX 09:29 JFK 12:29
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86