[C + +] The difference between a static link library and a dynamic link library

Source: Internet
Author: User

The difference between a static link library and a dynamic link library

One, Static link library

compilation, compilation, compiling, precompiled--links

Linux:

To generate a target file

g++-C Source.cpp-o SOURCE.O

Package as a static link library

AR-CRV Source.a SOURCE.O

Using the static link library

g++ test.cpp-l Static link library directory-l static link library name no suffix

Second, dynamic link library

The use of dynamic link libraries is a two-point problem to circumvent static link libraries.

One is the problem of multiple replicas, for the static library is compiled at the time of compilation into the source code, at run time no longer have any relationship with the static library. The advantage is fast, but it creates a waste of space.

The other is the issue of consistency and update issues, if it is a static library, if the static library is updated, then need to recompile the code, and prompt users to download the entire software, which will cause a lot of constant, wasting a lot of bandwidth. In the case of a dynamic library, only the corresponding dynamic link libraries need to be updated, and the entire software does not need to be modified.

Linux platforms:

To generate a target file

g++-fpic Source.cpp-o SOURCE.O

Dynamic Link Library

g++-shared source.so SOURCE.O

or merge into one command

g++-fpic-shared source.so Source.cpp

There are some issues to be aware of when locating a dynamic link library in use, the default dynamic-link library is under/lib or/usr/lib

If you want to modify the/etc/ld.so.cache file under a different folder

[1] http://www.cnblogs.com/skynet/p/3372855.html

[C + +] The difference between a static link library and a dynamic link 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.