遇到一个问题,平台上的library版本被更新导致无法开机:
正常:
lrwxrwxrwx 1 19545752 19545752 14 Aug 11 2020 libxx.so -> libxx.so.2.0
-rw-rw-r-- 1 19545752 19545752 326368 Aug 11 2020 libxx.so.2.0
-rwxrwxr-x 1 19545752 19545752 768172 Aug 11 2020 libxx.so.3.0
开机后变为:
lrwxrwxrwx 1 root root 14 Aug 11 2020 libxx.so -> libxx.so.3.0
-rw-rw-r-- 1 19545752 19545752 326368 Aug 11 2020 libxx.so.2.0
-rwxrwxr-x 1 19545752 19545752 768172 Aug 11 2020 libxx.so.3.0
百思不得其解,查看代码也没有地方改变,最终发现是ldcofig会更新库的版本,源码中的注释:
The algorithm is basically:
for all libraries in the directory do
get soname of library
if soname is already in list
if new library is newer, replace entry
otherwise ignore this library
otherwise add library to list
For example, if the two libraries libxy.so.1.1 and libxy.so.1.2
exist and both have the same soname, e.g. libxy.so, a symbolic link
is created from libxy.so.1.2 (the newer one) to libxy.so.
libxy.so.1.2 and libxy.so are added to the cache - but not
libxy.so.1.1. */
/* Information for one library. */
NAME
ldconfig - configure dynamic linker run-time bindings
SYNOPSIS
/sbin/ldconfig [ -nNvXV ] [ -f conf ] [ -C cache ] [ -r root ] directory ...
/sbin/ldconfig -l [ -v ] library ...
/sbin/ldconfig -p
DESCRIPTION
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in
the trusted directories, /lib and /usr/lib (on some 64-bit architectures such as x86-64, lib and /usr/lib are the trusted directories for 32-bit libraries, while /lib64 and
/usr/lib64 are used for 64-bit libraries).
解决方式就是增加-X参数:
-X Don't update links. Unless -N is also specified, the cache is still rebuilt.