#include stdio.h>
#include "src.h"
int sum(int a,int b)
{
return (a+b);
}
#include stdio.h>
extern int sum(int a,int b);
/*
#include stdio.h>
#include "mysum.h"
*/
int main()
{
int a,b,c=0;
printf("input a and b:\n");
scanf("%d %d",a,b);
c = sum(a,b);
printf("c = %d\n",c);
return 0;
}
gcc -c -fPIC mysum.c mysum.h //生成mysum.o文件
gcc -shared -fPIC -o libmysum.so mysum.o //生成动态库文件,默认的命名方式为lib+名称.so
gcc -o main main.c -L. -lmysum -Wall
或
gcc -o main main.c -lmysum -Wall
gcc -o main1 -Wl,-rpath,.-L. -louyang main.o