Linux下静态库的制作

一.静态库概念
1.库是预编译的目标文件的集合,它们可以被链接进程序。静态库以后缀为”.a”的格式文件存在。
2.标准系统库可在目录/usr/lib与/lib中找到
3.2.静态库的优点:1>节约编译时间 2>可以不用提供源代码,对代码施行封装

二、编译过程
1.hello.c

void display()
{
	printf("hello world!\n");
	return;
}

2.hello.h

#ifndef _HELLO_H_
#ifdef  _HELLO_H_
	void display();
#endif

3.main.c调用

#include
#include"hello.h"

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

编译:
1—>gcc -c hello.c -o hello.o
2—>ar -rcs libhello.a hello.o
3—>gcc -o display main.c libhello.a
运行结果:
在这里插入图片描述

你可能感兴趣的:(Linux,c)