Building my own static library:
1. create files: fred.c and bill.c
#include <stdio.h>
void bill(char* arg)
{
printf("bill: you passed %s/n",arg);
}
#include <stdio.h>
void fred(int arg)
{
printf("fred: you passed %d/n", arg );
}
2. run command: cc -c bill.c fred.c
(use the '-c' parameter to prevent the compiler from generating the executable binary file )
3. create a '.h' file : lib.h:
/* This is lib.h. It declares the functions fred and bill for users.*/
void bill(char* );
void fred (int );
4. write a program.c that calls bill():
#include "lib.h"
int main()
{
bill("Hello world.");
return 0;
}
5. run command : cc -c program.c
cc -o program program.o bill.o
we can run program now: cmd: ./program
or:
6. build our own library cmd: ar crv libfoo.a bill.o fred.o
(cmd not required in gcc): ranlib libfoo.a
7. run: cc -o program program.o libfoo.a
run : ./program