1、编写tax.c
/********************************************
* tax.c
* time 2016
* 个人税收
* ******************************************/
#include <stdio.h>
int tax(int salary, int insurance)
{
int tax_salary = salary - insurance;
int tmp = tax_salary - 3500;
if ( tmp <0 )
{
printf("you donn't need to tax!");
return 0;
}
if ( tmp <= 1500 )
return ( tmp*0.03-0);
if ( (tmp > 1500) && (tmp <= 4500 ))
return tmp*0.1 - 105;
if ( (tmp > 4500) && (tmp <= 9000))
return tmp*0.2 - 555;
if ( (tmp > 9000) && (tmp <= 35000))
return tmp*0.25 - 1005;
if ( (tmp > 35000) && (tmp <= 55000))
return tmp*0.3 - 2755;
if ( (tmp > 55000) && (tmp <=80000))
return tmp*0.35 - 5505;
if( (tmp > 55000) && (tmp <=80000))
return tmp*0.45 - 13505;
}
2、编写tax.h
int tax(int salary, int insurance);
3、编写mytax.c
#include <stdio.h>
#include "tax.h"
void main()
{
int my_tax =0;
my_tax = tax(9500,1200);
printf("I need tax %d\n",my_tax);
}
4、编译 tax.c 文件 ,会生成 tax.o 文件
gcc -c tax.c
5、生成动态库文件 libtax.so
gcc -shared -fPIC tax.o -o libtax.so
6、复制libtax.so文件到/usr/lib库中
cp libtax.so /usr/lib/
7、编译mytax.c 文件
gcc mytax.c -ltax -o mytax
8、查看是否成功调用以创建的动态库
readelf -d mytax
成功调用libtax.so 动态库文件!!!