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

前端 未结 6 1021
悲&欢浪女
悲&欢浪女 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:15

    you can use union, like this:

    union {
        void *ptr;
        void (*init_google_logging) (char* argv0);
    } orig_func;
    
    orig_func.ptr = dlsym (RTLD_NEXT, "_ZN6google17InitGoogleLoggingEPKc");
    
    orig_func.init_google_logging (argv0);
    

提交回复
热议问题