dorainm@thinkpad:~/workroom/lib$ cd libtest/src
dorainm@thinkpad:~/workroom/lib/libtest/src$ more libtest.h
#ifndef __LIBTEST_H__
#define __LIBTEST_H__
extern int test_add( int a );
extern int test_sub( int a );
#endif
dorainm@thinkpad:~/workroom/lib/libtest/src$
功能函数1源码libtest1.c
dorainm@thinkpad:~/workroom/lib/libtest/src$ more libtest1.c
#include <stdio.h>
#include "libtest.h"
extern int test_add( int a )
{
return (a+1);
};
dorainm@thinkpad:~/workroom/lib/libtest/src$
功能函数2源码libtest2.c
dorainm@thinkpad:~/workroom/lib/libtest/src$ more libtest2.c
#include <stdio.h>
#include "libtest.h"
dorainm@thinkpad:~/workroom/lib/libtest/src$ cd ../example/
dorainm@thinkpad:~/workroom/lib/libtest/example$ more main.c
#include <stdio.h>
#include <libtest.h>
int main( void )
{
int a = 7;
printf( "%d => %d\n", a, test_add(a) );
printf( "%d => %d\n", a, test_sub(a) );
return 0;
};
dorainm@thinkpad:~/workroom/lib/libtest/example$
我们来编译这个程序
dorainm@thinkpad:~/workroom/lib/libtest/example$ make
gcc -Wall -o libtest-example main.c -ltest
dorainm@thinkpad:~/workroom/lib/libtest/example$ ls
libtest-example main.c Makefile
dorainm@thinkpad:~/workroom/lib/libtest/example$