#include <iostream>
#include <dlfcn.h>
using namespace std;
typedef int (*pStrLenFun)(char *str);
typedef char *(*pStrCopyFun)(char *desc, char *src);
int main(int argc, char *argv[])
{
char src[]="Hello Dymatic";
char desc[80];
pStrLenFun fun1;
pStrCopyFun fun2;
void *phandle = NULL;
char *perr = NULL;
phandle = dlopen("libslstrlen.so", RTLD_LAZY);//RTLD_NOW
if(!phandle)
{
printf("Failed Load library!\n");
}
perr = dlerror();
if(perr != NULL)
{
printf("%s\n",perr);
return 0;
}
fun1 = (pStrLenFun)dlsym(phandle, "StrLen");
perr = dlerror();
if(perr != NULL)
{
printf("%s\n",perr);
return 0;
}
fun2 = (pStrCopyFun)dlsym(phandle, "StrCopy");
perr = dlerror();
if(perr != NULL)
{
printf("%s\n",perr);
return 0;
}
printf("The string is: %s\n",src);
printf("the string length is: %d\n",fun1(src));
printf("the string copyed:%s\n",fun2(desc,src));
return 0;
}