一. 相关函数:dlopen(打开共享库),dlsym(查找符号),dlerror(错误信息),dlclose(关闭共享库)
1. dlopen() 原型:void* dlopen(const char *filename, int flag);
2. dlsym()
3. dlerror()
4. dlclose()
二. 源码实例
1. 动态库文件:lib.c,lib.h
#include
void output(int index)
{
printf("Printing from lib.so. Called by program %d\n", index);
}
#file:lib.h
#ifndef LIB_H
#define LIB_H
void output(int index);
#endif
2. main.c#include
#include
int main()
{
void *handle;
void (*fun)(int);
char* error;
handle = dlopen("/home/hotpatch/dynamic_lib/lib.so", RTLD_NOW);
if(NULL == handle)
{
printf("Open library error.error:%s\n",dlerror());
return -1;