Linux operating system: Specify the search path of the dynamic library (. so)

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.