linux so动态库调用例子

来源:互联网 发布:网络自动备份软件 编辑:程序博客网 时间:2024/05/29 14:55

#include <dlfcn.h>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    char *p;   
    void *lib;
    lib = dlopen("./libCC.so", RTLD_LAZY);
    if (lib == NULL)
    {
        cout << "NULL" << endl;
        p = dlerror();
        cout <<"load err"<< p << endl;
    }
    else
    {
        cout <<"load succ "<< std::hex << lib << endl;
    }

    typedef void (*initFun)();
    typedef bool (*encodeFun)(double lo,double la, double& loOut, double& laOut);
    initFun ini = (initFun)dlsym(lib, "initialize");
    encodeFun encode = (encodeFun)dlsym(lib, "encode");
   .....

    ini();

   ....
    return 0;
}