How to fix C warning 'implicit declaration of function dlsym'
Problem:
You have C code like
dlsym(RTLD_NEXT, 'myfunc');
but when you try to compile it you see a warning message like
main.c: In function ‘main’:
main.c:3:5: warning: implicit declaration of function ‘dlsym’ [-Wimplicit-function-declaration]
dlsym(RTLD_NEXT, 'myfunc');
Solution
Add
#include <dlfcn.h>
at the top of the source file where the error occured. This will include both dlopen
, dlsym
and related definitions like RTLD_NEXT
.