link library (ii) UNIX department

Source: Internet
Author: User

There are two types of Unix link libraries: Static libraries and dynamic libraries.

The static library links the Access program in the link time, the runtime does not need the link library existence.

Dynamic libraries are loaded (statically loaded) at program startup, or loaded (dynamically loaded) at run time.

LDD command: View the dynamic libraries associated with the program.

Linux has a dynamic library file with the extension ". So" (Shared Object). By convention, all dynamic library file names are in the form of libname.so (possibly by adding a version number to the name). Thus, the thread function library is called libthread.so. The file name of the static library is libname.a. The file name of the shared archive is libname.sa. Shared archive is just a transitional form that helps people shift from static libraries to dynamic libraries.

Look at the static library first

First, the static library liblt.a.

1. $ gcc-o lt.o-c lt.c

2. $ ar cqs liblt.a lt.o

Furthermore, links,

1. $ gcc TEST.O liblt.a-o test

This time to see his reference library situation.

1. $ LDD Test

2. Linux-gate.so.1 => (0xffffe000)

3. Libc.so.6 =>/lib/libc.so.6 (0xb7e29000)

4./lib/ld-linux.so.2 (0xb7f6e000)

Dynamic Library

Make the dynamic library liblt.so.

1. $ gcc-o lt.o-c lt.c

2. $ gcc-shared-wall-fpic-o liblt.so lt.o-shared

This option specifies that the build dynamic connection library (which allows the connector to generate an export symbol table of type T, and sometimes a weakly connected W-type export symbol) without the flag external program cannot connect. Equivalent to an executable file

-fpic: For code that is compiled as location independent, the compiled code is location-dependent without this option, so dynamic loading is a way to copy the code to meet the needs of different processes, but not the purpose of real code segment sharing.

-L.: Indicates the library to connect to in the current directory

-ltest: When the compiler looks for a dynamic connection library, there is an implied naming rule, that is, precede the given name with Lib, followed by. So to determine the name of the library Ld_library_path: This environment variable indicates that the dynamic connector can load the path of the 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.