Analyze precautions for using Linux dynamic libraries

Source: Internet
Author: User

Do you know about the operating system? Now many people should know about Microsoft. In fact, Linux is becoming more and more popular with programmers. Here, we will introduce in detail the issues that should be paid attention to when using the Linux dynamic library, and play a certain role in your learning to use the Linux dynamic library.

1. Whether it is an explicit or implicit call to a dynamic library, you must use

The ldconfig tool adds the path of the dynamic library to the system library list. Otherwise, an error occurs during running.

2. You can use the ldd command to check which shared libraries are used by the program.

The usage of the ldd command line is as follows:

Ldd [-- version] [-v | -- verbose] [-d | -- data-relocs] [-r | -- function-relocs] [-- help] FILE...

The options are described as follows:

(1) -- version: This option is used to print the version number of ldd.

(2)-v or -- verbose: This option instructs ldd to output as detailed as possible about the dependent Dynamic Link Library.

(3)-d or -- data-relocs: This option is relocated and displays non-existent functions.

(4)-r or -- function-relocs: This option executes data object and function relocation, and reports non-existing objects.

(5) -- help: This option is used to print the help information of ldd.

We generally use the-v option.

Now let's look at several instances.

(1) results of static database connection

 
 
  1. #ldd main  
  2. libc.so.6 => /lib/tls/libc.so.6 (0xb74ad000)  
  3. /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb75eb000) 

It can be seen that when a static library is used, the Library has been compiled into a part of the program, so ldd output is only used.

System Library.

(2) result of implicit connection with a dynamic database

 
 
  1. libtest.so => /root/exercise/libtest.so (0xb75e2000)  
  2. libc.so.6 => /lib/tls/libc.so.6 (0xb74ab000)  
  3. /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb75eb000) 

It can be seen that when dynamic libraries are implicitly used, all the dynamic libraries (including the system and user) used will be displayed.

(3) results of dynamic library explicit connection

 
 
  1. ldd main  
  2. libdl.so.2 => /lib/libdl.so.2 (0xb75e1000)  
  3. libc.so.6 => /lib/tls/libc.so.6 (0xb74aa000)  
  4. /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb75eb000) 

It can be seen that when a dynamic library is explicitly used, the program no longer saves the information for opening the dynamic library during running, and only retains the information of the system library used.

This is similar to the output when the static library is used. The above issues should be noted when using the Linux dynamic library.

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.