Linux dynamic static link library problem __linux

Source: Internet
Author: User

1 Linux Dynamic Static library is what.

Some code is born into a code package for other programs to call, that is, dynamic static library. Static and dynamic libraries are not executable files, but are compiled from source files.

Linux, the static function library (corresponding to the. a file), the Shared function library (dynamic library, corresponding to the. so file).

The. A file is similar to a Windows. dll file (Dynamic Link Library), which is analogous to Windows. File. o files, which are equivalent to. obj files in Windows.


2 The difference between dynamic and static library

Static libraries and dynamic libraries are two ways to share program code, and the difference is:

(1) The static library is copied to the target program code in the link phase of the program, and the static library is no longer needed when the program is running.

(2) Dynamic Library in the link phase, and will not be linked to the target program code, but the program at run time by the system dynamically loaded into memory for the program calls, so the program is also required to run the existence of a dynamic library.

The advantage of using dynamic libraries is that the system only needs to load one dynamic library at a time, and different programs can get copies of the same dynamic libraries in memory, thus saving a lot of memory.


3 Use of the library

If the library name libsomething.a, link, plus the compilation option-lsomething.

For example, the math library is LIBM.A, and the compilation option is-LM.

4 generation of Linux library files

(1) Generate. So file:

$GCC test_a.c Test_b.c-fpic-shared-o libtest.so

$GCC test.c-l.-ltest-o Test

-shared Specify build dynamic link library

-fpic represents code that is compiled as location-Independent

-L. Represents the library to be connected under the current directory

-ltest compiler has implied naming rules when looking for dynamic connection libraries



The. So file is also a file in elf format.

$GCC-G-fpic-c src.c-o LIBSRC.O

$GCC-G-shared-wi,-soname,libsrc.so-o libsrc.so libsrc.o-l<?

(2) generate. A file

$GCC-O fun.o fun.c

$ar-RC Fun.a FUN.O

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.