Dynamic link time, search path order at execution time:
1. Use the dynamic library search path specified by-l when compiling the target code;
2. Environment variable LD_LIBRARY_PATH the specified dynamic library search path;
3. The dynamic library search path specified in the configuration file/etc/ld.so.conf;
4. Default dynamic library search path/lib;
5. The default dynamic library search path/usr/lib.
In the 3~5 step above, you no longer need to manually specify the dynamic library search path.
There is a command that can be configured to update the default search path:
Ldconfig
The purpose of the Ldconfig command is to search for a shareable dynamic-link library (formatted as described above, lib*.so*) in the default search directory (/lib and/usr/lib) and in directories listed in the dynamic library configuration file/etc/ld.so.conf. It then creates the required connection and cache files for the dynamic loader (ld.so). The cached file defaults to/etc/ld.so.cache, which holds the list of dynamically linked library names that have been sorted out.
For example:
I compiled a dynamic library file, copy to/usr/lib, then use Ldconfig search for my copy of the past is already in the ability to configure success;
Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/
root@ubuntu:/home/v0id/tools/android-ndk-r9c/samples/hello-jni# CP Libs/x86/libhello-jni.so/usr/lib
root@ubuntu:/home/v0id/test# Ldconfig-p | grep JNI
without any return results;
After you configure using the Ldconfig command:
root@ubuntu:/home/v0id/test# Ldconfig/usr/lib
root@ubuntu:/home/v0id/test# Ldconfig-p | grep JNI
root@ubuntu:/home/v0id/test# Ldconfig-p | grep JNI
Libhello-jni.so (ELF) =>/usr/lib/libhello-jni.so
Example 2:
is not in the default directory, the contents of the/etc/ld.so.conf file are:
Include/etc/ld.so.conf.d/*.conf
Then create a yygytest.conf file in/etc/ld.so.conf.d/, and configure a new path to the library, as follows:
/home/v0id/test/yygylib
At the same time, the libhello-jni.so dynamic library placed in the/usr/lib directory is moved to the/home/v0id/test/yygylib directory, then the configuration of the dynamic library path is updated using Ldconfig, and the command is as follows:
root@ubuntu:/etc/ld.so.conf.d# mv/usr/lib/libhello-jni.so/home/v0id/test/yygylib/
root@ubuntu:/etc/ld.so.conf.d# Ldconfig-p | grep JNI
Libhello-jni.so (ELF) =>/usr/lib/libhello-jni.so
root@ubuntu:/etc/ld.so.conf.d# Ldconfig
root@ubuntu:/etc/ld.so.conf.d# Ldconfig-p | grep JNI
Libhello-jni.so (ELF) =>/home/v0id/test/yygylib/libhello-jni.so
When a dynamic library file is deleted from the directory, use Ldconfig again to update the configuration of the path of the dynamic library: _ (
Author: csdn Blog Yygydjkthh