Linux application Development-Design Static Library

Source: Internet
Author: User

Linux application Development-Design Static library An application


function library (user) and system call (Linux kernel)


Fenhe classification


1 Static link library (*.A)


A program uses a library of functions


2 Dynamic link library (*.so)


Multiple programs can use the same function library to reduce the size of the program


3 Static cubby Dynamic Library Large


Three make your own static library


1 gcc-c mylib.c-o MYLIB.O


2 ar cqs LIBMYLIB.A mylib.o


3 Copy the good LIBMYLIB.A to the/usr/lib directory


iv using a static library of your own creation


1 Linux default link dynamic library, to link to a static library: gcc-static Hello.c-o helloc.out


2 Use your own dynamic library:


Create a main.c to call your own library


Create a prototype declaration of a function inside the main.h that contains the function library to be called


Compile call Gcc-static-lmylib main.c-o main.out-l parameter for calling your own Lib


When GCC links, only the C function library is linked by default, and for other libraries, you need to use the-l option to indicate that a link needs to be displayed.


Linux directory/usr/lib and/lib stored in the corresponding LIB, commonly used LIBMYLIB.A to name, the front Lib must be added


Five simple addition calculator case List


1 Writing ADD.C


2 compile into Static library: gcc-c add.c-o add.o ar cqs libadd.a add.o


3 Copy to/USR/LIB:CP libadd.a/usr/lib/


4 Create MAIN.C to call the Add function as the main function to create a main.h to contain the declaration of the Add function


5 Compile and debug: Gcc-static-ladd main.c-o main.out


6 run./main.out

Linux application Development-Design Static 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.