Create, view, extract, and modify static databases in Linux (*.)

Source: Internet
Author: User

First, the static library file is packaged into multiple target files. In windows, the static library file suffix is. in linux, the static library file suffix is. a (a is short for archive, that is, document files ).

To put it bluntly, go to the topic.

 

   addition ( a ,   result=a+  }

Multiplication. c

     result=a*  }

 

 

 $ gcc - $ gcc -c multiplication.c

Among them, option-c enables gcc to compile only the source code into a. o file.

The current folder contains two. o files.

  addition.c multiplication.c addition.o multiplication.o

 

 

 $ ar cr libarith.a  addition.o multiplication.o

Cr indicates create, and a static library file libarith. a is created.

 

 

Before using the library file, you must first create a header file header. h, which contains the declaration of functions implemented in the library file.

  #include<stdio.h>  addition( a,  multiplication( a, b);

Then create a c program example. c to call the function.

  #include     result=addition(, printf( result=multiplition(, printf(   }

Compile example. c

 $ gcc example.c libarith.a -o example

The parameter after option-o specifies the executable file name generated by the compiler. If-o is not added, the default executable file name generated is a. out.

Run example

 $./ addtion result : multiplication result :

 

 

   multiplition.o

If you want to view which functions are included in the library file, you can use nm libarith. a to view which libraries need to be called by the executable file, you can use lld example to view them.

 

  $ cp libarith.a file/     multiplition.o

 

 

Suppose you already have a target file subtraction. o

     subtraction.o

If the subtraction. o file already exists in the library file, it overwrites the old one with a new one.

 

 

    subtraction.o

 

Reference Source: http://www.thegeekstuff.com/2010/08/ar-command-examples/

Related Article

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.