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

关于 ldconfig 的一个疑问

  •  
  •   MartinWu ·
    Martwu · 28 天前 · 818 次点击

    我用 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
    vivisidea
        1
    vivisidea  
       28 天前
    ```
    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
        2
    vivisidea  
       28 天前
    命名里面再加一个 build 时间戳呢
    MartinWu
        3
    MartinWu  
    OP
       28 天前
    @vivisidea #1 感谢!知道原因就好解决了。我这就处理下。
    MartinWu
        4
    MartinWu  
    OP
       28 天前
    @vivisidea #2 我最后改成 libhaha.so.5.ts.fb9da2af

    ts 取的是对应 commit 的 commit time
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2469 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:40 · PVG 23:40 · LAX 08:40 · JFK 11:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.