原始问题:
linux下写一个dlopen函数可以调用的so动态库,给出代码
include <stdio.h>
include <dlfcn.h>
int main()
{
// open the library
void *handle = dlopen("./libhello.so", RTLD_LAZY);
// reset errors
dlerror();
// load the symbol from library (function add)
typedef int (*hello_t)();
hello_t hello = (hello_t)dlsym(handle, "hello");
const char *dlsym_error = dlerror();
if (dlsym_error) {
fprintf(stderr, "%s ", dlsym_error);
exit(1); } printf("calling hello(): %d ", hello()); // close the library dlclose(handle); }
Prev:甲流症状