main.c
来自「程序代码使用说明: (1)所有源代码目录下都提供了Makefile(非Qt)」· C语言 代码 · 共 37 行
C
37 行
#include <dlfcn.h>#include <stdio.h>int main(){ fprintf(stdout, "Press Enter key to load library... \n"); getchar(); // open the library fprintf(stdout, "Loading library libprint.so... \n"); void* handle = dlopen("./libprint.so", RTLD_LAZY); if (!handle) { fprintf(stderr, "Failed to open library: %s \n", dlerror()); exit(-1); } // load the symbol fprintf(stdout, "Loading symbol print_foo()... \n"); typedef void (*print_t) (); dlerror(); // reset error print_t pfoo = (print_t)dlsym(handle, "print_foo"); const char* dlsym_error = dlerror(); if (dlsym_error) { fprintf(stderr, "Failed to load symbol: %s \n", dlsym_error); dlclose(handle); exit(-1); } fprintf(stdout, "Calling print_foo()... \n"); pfoo(); fprintf(stdout, "Closing library... \n"); dlclose(handle); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?