//test.c
#include <stdio.h>
Test(void)
{ printf("Test ok...\n");}
//test.h
#ifndef _TEST_H
#define _TEST_H
void Test(void)
#endif//_TEST_H
//main.c
#include <stdio.h>
#include "test.h"
int main(int argc, char *argv[])
{
Test();
return 0;
}
生成静态库步骤:
1编译: gcc -o test.o test.c
2生成库文件: ar - ./ libtest.a test.o
3使用:
#makefile
main: main.o
gcc -o $@ -L./ $< -lTest
main.o: main.c
gcc -I./ -o $@ -c $<
clean:
rm *.o main