Linux调用so库文件里面的指定函数

yyqng / 2023-05-05 / 原文

代码示例:

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

typedef int(*Func)(void*);
int callFunc(dtInterp_t a)
{
    void* handle = dlopen("*.so", RTLD_LAZY);
    Func func = (Func)dlsym(handle, "funcName");
    func(a);
    dlclose(handle);
    return 0;
}