Rawat
Rawat

Reputation: 469

dlsym function return type

i am loading libslabhidtouart.so file using dlopen() without any error but when i am calling a function using dlsym() ,I got no such process error

here is my code

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;
    } 

/**** return type of function HidUart_GetNumDevices is int,so is there any casting problem or my method signature is wrong or what else plz guide me,i am no good at c .

Upvotes: 1

Views: 1048

Answers (1)

dvo
dvo

Reputation: 350

I also got strange "No such process" errors, yet already directly upon a dlopen() call within OpenSSL:

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

It turned out that the referenced DLL (or .so file) exists, but has a dependency on some other library (cygp11-2.dll in my case) that could not be resolved in the context of the application's process (taking into account its PATH environment variable setting). In this case, use ldd (or cygcheck.exe if applicable) to see if all dependencies are correctly resolved.

So the "no such process" error message returned by dlerror() can be quite misleading.

Upvotes: 1

Related Questions