#include<iostream> #include <QLibrary> using namespace std; int main() { cout<<"this is a test!"<<endl; QLibrary *hello_lib = NULL; //写清楚库的路径,如果放在当前工程的目录下,路径为./libhello.so hello_lib = new QLibrary("./libsth.so"); cout<<"this is a test!"<<endl; //加载动态库 hello_lib->load(); if (!hello_lib->isLoaded()) { cout<<"load libhello.so failed!"<<endl; return 0; } //定义函数指针 typedef int (*Sub_t)(int,int); //resolve得到库中函数地址 Sub_t Sub = (Sub_t)hello_lib->resolve("sub"); if (!Sub) { cout<<"find address error!"<<endl; } else cout<<Sub(1,2)<<endl; //卸载库 hello_lib->unload(); return 0; }
说明,本代码原型来自于网络引用,具体地址稍后补上,感谢分享