Fire Station Building Institute (Bkjia.com)LinuxDocumentAs we all know, the default search paths for Linux dynamic libraries are/lib and/usr/lib. After a dynamic library is created, it is generally copied to these two directories. When a dynamic library is required for program execution and the dynamic library is not loaded into the memory, the system will automatically go to the two default search paths to find the corresponding dynamic library file, then load the file to the memory so that the program can use the functions in the dynamic library and other resources of the dynamic library. In Linux, in addition to the default search path, the search path of a dynamic library can be specified in the following three methods.
Method 1: Specify the dynamic library search path in the configuration file/etc/ld. so. conf.
You can specify the search path for a dynamic library by editing the configuration file/etc/ld. so. conf. After editing the file, you must run the ldconfig command to make the modified configuration take effect. We use Example 1 to describe this method.
Example 1:
Run the following command to use the source program pos_conf.c (see program 1) to create the dynamic library libpos. so. For detailed creation process, see [1].
# Gcc-c pos_conf.c # Gcc-shared-fPCI-o libpos. so pos_conf.o # # Include <stdio. h> Void pos () { Printf ("/root/test/conf/lib \ n "); } Procedure 1: pos_conf.c |
Run the following command to compile main. c (see Program 2) to generate the pos of the target program.
# Gcc-o pos main. c-L.-lpos # Void pos (); Int main () { Pos (); Return 0; } Program 2: main. c |
Then, move the library file to the/root/test/conf/lib directory.
# Mkdir-p/root/test/conf/lib # Mv libpos. so/root/test/conf/lib # |
Finally, edit the configuration file/etc/ld. so. conf and add a line "/root/test/conf/lib" to the file ".
- Four pages in total:
- Previous Page
- 1
- 2
- 3
- 4
- Next Page