/**********************************************
* 使用Linux下C++的动态链接库.So文件
* void *pdlHandle;
* pdlHandle = dlopen("/home/fengsy/len/Len.So/len.so", RTLD_LAZY);
* pnswap=dlsym(pdlHandle, "swap");
*********************************************/
[fengsy@ctihost Len.So]$ cat call.c
#include
#include
#include
#include
void *(*pnswap)(int *,int *);
main()
{
void *pdlHandle;
int a[1],b[1];
a[0]=1;
b[0]=2;
pdlHandle = dlopen("/home/fengsy/len/Len.So/len.so", RTLD_LAZY);
pnswap=dlsym(pdlHandle, "swap");
printf("a:%d b:%d/n",a[0],b[0]);
pnswap(a,b);
printf("a:%d b:%d/n",a[0],b[0]);
dlclose(pdlHandle);
}
-------------------------------------------------------------------------[fengsy@ctihost Len.So]$ cat len.cvoid swap(int *a,int *b){ printf("3333333/n"); int c; c=*b; *b=*a; *a=c;}