Linux最简单的静态库开发

1 编写头文件

  test.h代码:

#ifndef __TEST_H_
#define __TEST_H_

void sayHello(void);

#endif

2 编写代码

  test.c代码:

#include <stdio.h>
#include "test.h"

void sayHello()
{
        printf("Hello my friend.\n");
}

3 编译静态库

gcc -c test.c -I.
ar -r libtest.a test.o

4 编写main.c

  main.c的代码:

#include "test.h"

int main(){
        sayHello();
        return 0;
}

5 编译调用静态库

gcc main.c -ltest -L. -I.

 

posted @ 2020-03-28 20:34  ziwuxian  阅读(269)  评论(0编辑  收藏  举报