LPI学习之共享库

    技术2022-05-20  51

    Linux 系统上有两类根本不同的 Linux 可执行程序。第一类是静态链接的 可执行程序。静态可执行程序包含执行所需的所有函数 — 换句话说,它们是“完整的”。因为这一原因,静态可执行程序不依赖任何外部库就可以运行。

    第二类是动态链接的 可执行程序。动态可执行程序是不完整的 程序,它依靠外部共享库来提供运行所需的许多函数

     

    [root@rcc-pok-idg-2305 dev]# lddhttp://writeblog.csdn.net/PostEdit.aspx /sbin/sln         not a dynamic executable [root@rcc-pok-idg-2305 dev]# ls -l /bin/ln /sbin/sln -rwxr-xr-x 1 root root  31888 Oct 30  2008 /bin/ln -rwxr-xr-x 1 root root 613394 Jan  5  2009 /sbin/sln

     

    [root@rcc-pok-idg-2305 dev]# ldd --help Usage: ldd [OPTION]... FILE...       --help              print this help and exit       --version           print version information and exit   -d, --data-relocs       process data relocations   -r, --function-relocs   process data and function relocations   -u, --unused            print unused direct dependencies   -v, --verbose           print all information For bug reporting instructions, please see: <http://www.gnu.org/software/libc/bugs.html>.

     

    ldd的作用: print shared libery dependency。

     

    动态装入器(dynamic loader):

     

    动态装入器找到共享库要依靠两个文件 — /etc/ld.so.conf 和 /etc/ld.so.cache 。

    ld.so.conf 文件包含一个所有目录(/lib 和 /usr/lib 除外,它们会自动包含在其中)的清单,动态装入器将在其中查找共享库。

    但是在动态装入器能“看到”这一信息之前,必须将它转换到 ld.so.cache 文件中。可以通过运行 ldconfig 命令做到这一点:

    # ldconfig

    当 ldconfig 操作结束时,您会有一个最新的 /etc/ld.so.cache 文件,它反映您对 /etc/ld.so.conf 所做的更改。从这一刻起,动态装入器在寻找共享库时会查看您在 /etc/ld.so.conf 中指定的所有新目录。

     

    所有的 Linux 分发版都使用某种形式的软件包管理来安装、更新和卸载软件包。与直接从源代码安装相比,软件包管理有明显优势:

    易于安装和卸载易于更新已安装的软件包保护配置文件轻松跟踪已安装文件

     


    最新回复(0)