c++实现加载so动态库中的资源
实例如下:
#include<stdio.h> #include<dlfcn.h> #include<stdlib.h> #include<iostream> //编译命令g++-m32EncodeOrDecode.cpp-ldl-oedcode //名字通过nm-Dxxxxxx.so获取 usingnamespacestd; intmain(intargc,char**argv){ void*handle=dlopen("./libpub_com_service.so",RTLD_LAZY); if(!handle){ printf("openlibpuberror,dlerror=%s\n",dlerror()); return-1; } stringsrc="05d7151349b7fe9b54306d90f9c938b3"; stringdesKey="pub.%?d5";//58 printf("start..src=[%s].....size=[%d].\n",src.c_str(),src.size()); //encode typedefstring(*encode_t)(conststringencodeSrc,conststringencodeKey); encode_tencode=(encode_t)dlsym(handle,"_ZN10NS_PUB_API9DesEncodeESsSs"); if(!encode){ printf("notfoundencodefunction,dlerror=%s\n",dlerror()); dlclose(handle); return-1; } stringencodeStr=encode(src,desKey); printf("gettheencodefunctionsuccess..encodeStr=[%s].....size=[%d]\n",encodeStr.c_str(),encodeStr.size()); //decode typedefbool(*decode_t)(conststringdecodeSrc,conststringdecodeKey,string&outResult); decode_tdecode=(decode_t)dlsym(handle,"_ZN10NS_PUB_API9DesDecodeESsSsRSs"); if(!decode){ printf("notfounddecodefunction,dlerror=%s\n",dlerror()); dlclose(handle); return-1; } stringdecodeOut; boolret=decode(encodeStr,desKey,decodeOut); printf("getthedecodefunctionsuccess...ret=[%d]...decodeOut=[%s].....size=[%d]\n",ret,decodeOut.c_str(),decodeOut.size()); //end dlclose(handle); return0; }
以上就是小编为大家带来的c++实现加载so动态库中的资源全部内容了,希望大家多多支持毛票票~