1

我正在使用 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 。

4

1 回答 1

1

我也收到了奇怪的“没有这样的过程”错误,但已经直接dlopen()在 OpenSSL 中调用:

2675996:error:25066067:lib(37):func(102):reason(103):dso_dlfcn.c:187:filename(./engine_pkcs11.dll): No such process

事实证明,引用的 DLL(或 .so 文件)存在,但依赖于其他一些库(cygp11-2.dll在我的情况下),这些库无法在应用程序进程的上下文中解析(考虑到其 PATH 环境变量设置) . 在这种情况下,使用ldd(或cygcheck.exe如果适用)查看是否正确解析了所有依赖项。

因此返回的“没有这样的过程”错误消息dlerror()可能会产生很大的误导性。

于 2016-04-14T12:59:50.843 回答