制作静态库方法步骤:
一、编辑待制.c文件
test.c
#include "test.h"
int add(int a, int b)
{
return a+b;
}
test.h
#ifndef __TEST_H_
#define __TEST_H_
int add(int a,int b);
#endif
二、编译.o文件命令
gcc -c test.c -o test.o
三、使用制作静态命令
ar rc libname.a test.o
四、测试
hello.c
#include <stdio.h>
#include "test.h"
int main()
{
printf("%d\n",add(4,9));
return 0;
}
gcc hello.c -o hello ./libtest.a
./hello