为什么程序可以使用未找到的动态库运行?

时间:2016-03-31 03:19:41

标签: linker dynamic-linking hana dynamic-library ldd

成功安装SAP HANA后,我可以看到sapstartsrv进程运行:

# ps -ef | grep sapstartsrv
xn1adm     2143      1  0 Mar29 ?        00:00:05 /usr/sap/XN1/HDB00/exe/sapstartsrv pf=/home/hana/shared/XN1/profile/XN1_HDB00_dhe2 -D -u xn1adm

但是在使用ldd命令检查sapstartsrv动态链接库之后:

# ldd /usr/sap/XN1/HDB00/exe/sapstartsrv
    linux-vdso.so.1 (0x00007ffd35a30000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fd1fe6b3000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fd1fe4ab000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fd1fe270000)
    libpam.so.0 => /lib64/libpam.so.0 (0x00007fd1fe061000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007fd1fde5e000)
    libuuid.so.1 => /usr/lib64/libuuid.so.1 (0x00007fd1fdc59000)
    libsapnwrfccm.so => not found
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fd1fd8d7000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fd1fd5d6000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fd1fd3bf000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd1fd1a2000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fd1fcdfb000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fd1fe8b7000)
    libaudit.so.1 => /usr/lib64/libaudit.so.1 (0x00007fd1fcbd8000)

我可以看到找不到libsapnwrfccm.so。但是为什么sapstartsrv程序可以在找不到动态库的情况下运行?

1 个答案:

答案 0 :(得分:1)

因为某些东西通过将链接器指向包含该库的目录来启动该程序。通常这是我设置环境变量LD_LIBRARY_PATH。例如:

LD_LIBRARY_PATH=/look/here/for/libs program

现在,运行时链接程序还会查找/look/here/for/libs以查找依赖于库program的库。