Tag: dlopen

dlsym / dlopen与运行时参数

我正在尝试做类似以下的事情 enum types {None, Bool, Short, Char, Integer, Double, Long, Ptr}; int main(int argc, char ** args) { enum types params[10] = {0}; void* triangle = dlopen(“./foo.so”, RTLD_LAZY); void * fun = dlsym(triangle, ars[1]); <> } 伪代码就像 fun = {} for param in params: if param == None: fun += void if param == Bool: […]

返回共享库符号表

例如: void* sdl_library = dlopen(“libSDL.so”, RTLD_LAZY); void* initializer = dlsym(sdl_library,”SDL_Init”); 假设没有错误,初始化程序将指向共享库libSDK.so中的函数SD_Init。 但是,这需要知道符号“SDL_Init”存在。 是否可能在库中查询其所有符号? 例如,在这种情况下,它将返回SDL_Init,函数指针以及libSDL.so导出的任何其他符号。

加载的库函数如何在主应用程序中调用符号?

加载共享库时,通过函数dlopen()打开,有没有办法在主程序中调用函数?

创建包含字符串的静态C结构

我正在尝试在Rust中创建一个动态库,它导出一个结构作为符号,将通过dlopen()加载到C程序中。 但是,当我访问结构中的第二个字符串时,我遇到了一些段错误,所以我做了一个小测试程序,试着弄清楚我做错了什么。 这是Rust代码(test.rs),使用“rustc –crate-type dylib test.rs”编译: #[repr(C)] pub struct PluginDesc { name: &’static str, version: &’static str, description: &’static str } #[no_mangle] pub static PLUGIN_DESC: PluginDesc = PluginDesc { name: “Test Plugin\0”, version: “1.0\0”, description: “Test Rust Plugin\0” }; 这是尝试加载库(test.c)的C程序,使用“gcc test.c -ldl -o test”编译: #include #include typedef struct { const char *name; const char *version; […]

在C中使用dlopen时,是否有一种优雅的方法来避免dlsym?

如果在运行时满足特定条件,我需要动态打开共享库lib.so 该库包含~700个函数,我需要加载它们的所有符号。 一个简单的解决方案是定义lib.so包含的所有符号的函数指针,使用dlopen加载库,最后使用dlsym获取所有符号的地址。 但是,考虑到函数的数量,实现此解决方案的代码非常麻烦。 我想知道是否存在更优雅和简洁的解决方案,可能适当使用宏来定义函数指针。 谢谢!