Linux static function library usage and production/dynamic ...

Source: Internet
Author: User

Use and fabrication of static function libraries

1. First create a. c file, write the function you want to use inside

2. The compilation does not link the birth into. o File gcc-c mylib.c-o mylib.o

3. Use AR CQS instruction to generate library files such as AR cqs LIBMYLIB.A mylib.o Note that the name of the generated. A file is prefixed with LIB, but it is not prefixed with

4. Copy the made LIBMYLIB.A into the/usr/lib

So a library function is made.

How to use the library function you made

Add the. h file in the directory where you want to use the. c File of the library function, which declares the library function to use

Include the header file in the program, using the ""

Gcc-static-lmylib Test.c-o Test-l represents the use of this function library


Making and using of dynamic function library

1. Same static

2.gcc-shared-fpic Mylib.o-o libmylib.so

3. Same static

Using: GCC test.c-lmylib-o test where-L indicates which link library to use

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.