Linux Static library and dynamic library

Source: Internet
Author: User

Static library (. a)

A deal.c usedeal.c

Focus

1. Gcc-c DEAL.C

Generate DEAL.O

2. AR-RSV LIBDEAL.A DEAL.O

Generate LIBDEAL.A

2.5 You can see which OBG files are contained in a static library by Ar-t LIBDEAL.A

3. Gcc-o usedeal usedeal.c-l./-ldeal

Generating an executable program Usedeal

4../usedeal

Dynamic libraries (. So)

Usedeal.c

Deal.h

Dynamic links

1. o File generation

Gcc-c-fpic-o DEAL.O deal.c

-C means only compilation (compile), not connection. The-o option is used to describe the output file name. GCC will generate a target (object) file DEAL.O.

Note the-fpic option. Pic refers to position independent Code. This option is required for shared libraries to enable dynamic connectivity (linking).

2. So file generation

Gcc-shared-o deal.so DEAL.O

The library file starts with Lib. The shared library file is suffixed with. So. -shared indicates that a shared library is generated.

3.gcc-o Test Usedeal.c-ldeal-l.

Generate Test executable program

./test

Dynamic loading

Cond..

It's too urgent to write a lot of places to add (╯-﹏-) ╯ (┷━━━┷

Reference

Http://www.cnblogs.com/vamei/archive/2013/04/04/2998850.html

Http://www.codeceo.com/article/linux-library.html

Linux Static library and 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.