我正在用 C 编写一个插件应用程序,我正在使用 dlopen/dlsym 动态加载某些函数的“实现”。例如,我有以下指向函数的指针
struct cti_t* (*create)() = 0;
我使用以下代码加载实现:
plugin_handle = dlopen ("xxx.so", RTLD_NOW);
//error checking
create = dlsym(plugin_handle, "cti_create");
//error checking
//call create for the specific implenetation
struct cti_t *dev = create();
“插件”通过以下方式定义 cti_create
struct cti_t* cti_create(int i) {
printf("Creating device lcl");
//do somenthing with i
return &lcl_cti;
}
所以它定义了一个整数参数,但一切正常,没有错误。问题是:用 dlsym 加载符号时是否可以进行一些参数类型验证?如何强制加载的符号具有我期望的签名?