How to correctly assign a pointer returned by dlsym into a variable of function pointer type?
问题 I am trying to use dlopen() and dlsym() in my code and compile it with gcc . Here is the first file. /* main.c */ #include <dlfcn.h> int main() { void *handle = dlopen("./foo.so", RTLD_NOW); if (handle) { void (*func)() = dlsym(handle, "func"); func(); } return 0; } Here is the second file. /* foo.c */ #include <stdio.h> void func() { printf("hello, world\n"); } Here is how I compile and run the code. $ gcc -std=c99 -pedantic -Wall -Wextra -shared -fPIC -o foo.so foo.c $ gcc -std=c99