我正在使用 dlopen() 加载 libslabhidtouart.so 文件而没有任何错误,但是当我使用 dlsym() 调用函数时,我没有遇到此类过程错误
这是我的代码
int main(int argc, char **argv)
{
typedef unsigned int DWORD;
typedef unsigned short WORD;
typedef int HID_UART_STATUS;
void *handle;
HID_UART_STATUS (*cosine)( DWORD*,WORD,WORD);
//typedef void (*simple_demo_function)(void);
char *error;
handle = dlopen("libslabhidtouart.so.1.0", RTLD_NOW);
if (!handle) {
fprintf(stderr, " %s\n", dlerror());
getchar();
exit(EXIT_FAILURE);
}
dlerror(); /* Clear any existing error */
/* Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
would seem more natural, but the C99 standard leaves
casting from "void *" to a function pointer undefined.
The assignment used below is the POSIX.1-2003 (Technical
Corrigendum 1) workaround; see the Rationale for the
POSIX specification of dlsym(). */
*(void **) (&cosine) = dlsym(handle, "HidUart_GetNumDevices");
if ((error = dlerror()) != NULL) {
fprintf(stderr, " %s\n", error);
getchar();
exit(EXIT_FAILURE);
}
getchar();
dlclose(handle);
exit(EXIT_SUCCESS);
return 0;
}
/**** 函数 HidUart_GetNumDevices 的返回类型是 int,所以是否有任何转换问题或我的方法签名错误或者还有什么请指导我,我不擅长 c 。