The Linux static library

 

 

Naming rules:

lib + + .a library name

Production steps

Generating a file corresponding to .o .c à .o

The resulting .o file names package ar rcs + static library (libMytest.a) + generated by all the .o 

Publish and use static libraries:

1) publish static

2) the header file

 

File as shown below:

  1) generate the corresponding .o file

  2) The resulting .o file package, and move to folder lib

  3) Verify library file data generated

  

Write a test code to use the image above function main.c

/***
 main.c
***/
#include<stdio.h>
#include"MyCalc.h"

int main()
{
    int a = 10;
    int b = 20;
    int result = a + b;
    printf("a + b = %d\n",result);
    return 0;
}

Compile and run:

Static library advantages and disadvantages:

View the contents of a static library

nm static library name

nm can view the contents of an executable program

 

advantage:

  1. 发布程序的时候,不需要提供对应的库
  2. 库的加载速度比较快

缺点:

  1. 库打包到应用程序中,库的体积很大
  2. 库发生了变化,需要重新编译程序。

Guess you like

Origin www.cnblogs.com/wanghao-boke/p/11293763.html