Dynamic link library and static link library under Linux What the hell is that? (ii) Compilation and use of dynamic link libraries

Source: Internet
Author: User

The previous article explains the compilation and use of static link libraries under Linux, let's talk about how to compile and use the dynamic link library.

The so-called dynamic link library, that is, compile time will not really put you reference to the library into your execution program, but in the execution time will be loaded related libraries, all use this library program can share a code, the benefit is that the executable program occupies a smaller space, and, if the library needs to upgrade, You do not need to recompile your program, just upgrade the relevant library.

Let's take a look at the compilation and use of the dynamic link library, the same code as in the above, respectively, SUM.C, sum.h, and main.c, the dynamic link library file under Linux is generally called libxxx.so.

192: Zch kane$lsmain.csum. Csum. h192: Zch kane$192: Zch kane$GCC-c-fpicsum. C-------FIPC tells the compiler to compile the source code into a shared object file, and PIC (position-independent code) means the non-positional dependency code192: Zch kane$lsmain.csum. Csum. hsum. O192: Zch kane$GCC-shared-fpic-o libsum.sosum. o--------generate a dynamic-link library file libsum.so192: Zch kane$lslibsum.so main.csum. Csum. hsum. O192: Zch kane$192: Zch kane$GCC-O sumappd main.c-l. -lsum---------Generating an executable program192: Zch kane$lslibsum.sosum. Csum. OMAIN.Csum. h SUMAPPD192: Zch kane$./SUMAPPD---------Run build results Num1+ Num2 =3

Dynamic link library and static link library under Linux What the hell is that? (ii) Compilation and use of dynamic link 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.