Usage of static and dynamic libraries in GCC

Source: Internet
Author: User

Http://blog.chinaunix.net/uid-25871104-id-3069931.html

1. How to generate a static library

The static library is just a collection of object objects. You can use the AR command to package the. o file into the. A static library. Assume that GCC has generated. o, B. o, C. o. Use the following command to generate libmylib. A # ar RCS libmylib. a. o B. o C. O
2. How to generate dynamic library is directly generated by GCC. Suppose a. C and B. C files. Use the following command to generate libmylib. So # gcc a. c B. C-o libmylib. So -- shared
3. How to Use the parameters related to the library in the library GCC:-L specifies the directory of the database to be searched, for example, specifying the current directory gcc-L. -l the name of the database to be linked plus the name of the database to be linked is libmylib. a, then gcc-l mylib, that is, head-to-end. -- Static: Use a dynamic library when linking -- generate a dynamic library using shared -- Static-libgcc Link Static libgcc library -- shared-libgcc link dynamic libgcc Library
It can be seen that the use of dynamic and static libraries is the same. If the same library has both dynamic and static libraries, the link to the dynamic library is prioritized unless static is used to force the use of static libraries.

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.