(1)write the C code document for the function
fred.c :
#include <stdio.h>
void fred(int arg)
{
printf("fred: the number is %d\n",arg);
}
the other is bill.c:
#include<stdio.h>
void bill(char *arg)
{
printf("bill: the string is %s\n",arg);
}
(2)compile the object file:
gcc -c fred.c bill.c
can born fred.o and bill.o
(3)creat the head file include the two functions,just declare the funtions
lib.h:
#include <stdlib.h>
void fred(int);
void bill(char *);
(4)use lib.h to write program.c:
#include<stdlib.h>
#include "lib.h"
int main()
{
fred(100);
bill("hello");
}
(5)compile the program
gcc-o program program.c fred.o bill.o
can born program
(6)combine fred.o and bill.o into static lib libfoo.a:
ar crv libfoo.a fred.o bill.o
(7)now can use libfoo.a to compile the program:
gcc -o program program.c libfoo.a
also can born program