Qt 动态加载动态库

#include 
#include 


int main(int argc, char *argv[])
{
    QLibrary *hello_lib = NULL;
    //写清楚库的路径,如果放在当前工程的目录下,路径为./libhello.so
    hello_lib = new QLibrary("/home/libhello.so");
    
    //加载动态库
    hello_lib->load();
    if (!hello_lib->isLoaded()) 
    {
        printf("load libhello.so failed!\n");
        return 0; 
    }
    
    //定义函数指针
    typedef void (*Fun)();
    
    //resolve得到库中函数地址
    Fun hello = (Fun)hello_lib->resolve("hello");
    if (hello)
    {
        hello();
    }
    
    //卸载库
    hello_lib->unload();
    return 0;
}

你可能感兴趣的:(Qt 动态加载动态库)