How to correctly assign a pointer returned by dlsym into a variable of function pointer type?

前端 未结 6 1036
悲&欢浪女
悲&欢浪女 2020-12-31 01:00

I am trying to use dlopen() and dlsym() in my code and compile it with gcc.

Here is the first file.

/* main.c          


        
6条回答
  •  悲&欢浪女
    2020-12-31 01:16

    The compiler only "tries to help", so you have to use two typecasts:

    #include 
    
    void (*func)() = (void (*)())(intptr_t)dlsym(handle, "func");
    

提交回复
热议问题