C++动态加载动态库
作者:
氕氘氚0921 | 来源:发表于
2020-06-02 14:32 被阅读0次#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int a = 0;
void *handle = dlopen("./libadd_c.so", RTLD_LAZY);
if(!handle)
{
printf("open lib error\n");
cout<<dlerror()<<endl;
return -1;
}
typedef int (*add_t)(int a, int b);
add_t add = (add_t) dlsym(handle, "add");
if(!add)
{
cout<<dlerror()<<endl;
dlclose(handle);
return -1;
}
a = add(3, 4);
printf("a = %d\n",a);
dlclose(handle);
return 0;
}
本文标题:C++动态加载动态库
本文链接:https://www.haomeiwen.com/subject/vduuzhtx.html
网友评论