Edit
max.h*********
int max (int, int);
max.c*********
#include "max.h"
int max (int a, int b)
{
Return (a > B)? A:B;
}
min.h*******
int min (int, int);
min.c*******
#include "Min.h"
int min (int a, int b)
{
Return (A<B)? A:B;
}
main.c**********
#include <stdio.h>
#include "max.h"
#include "Min.h"
int main (int argc, char** argv)
{
int a = ten, B = 20;
printf ("Max:%d", Max (A, b));
printf ("min:%d", Min (A, b));
return 0;
}
Compile
Build executable: gcc main.c max.c min.c-o test
To generate a static library:
Gcc-c max.c MIN.C
AR cr libtest.a MAX.O MIN.O
Gcc-o test Main.c-l.-ltest
To build a shared library:
Gcc-c-fpic max.c min.c
Gcc-shared-fpic-o libtest.so MAX.O MIN.O
Note:-LM connection math Library,-lpthread cable libraries,-G can be debugged
Makefile
MAIN:MAIN.O MAX.O MIN.O
Gcc-o main MAIN.O MAX.O MIN.O
MAIN.O:MAIN.C max.h Min.h
Gcc-c MAIN.C
MAX.O:MAX.C max.h
Gcc-c max.c
MIN.O:MIN.C Min.h
Gcc-c MIN.C
Clean
RM *.O
After simplification:
MAIN:MAIN.O MAX.O MIN.O
Gcc-o [email protected] $^
. C.O:
Gcc-c $<
Simple example of C program development process under Linux