I'm thinking this could be made into a utility and set of associated autoconf scripts. I want to be able to say in some central place "I want to weak-link against libfoo.so" and have it generate headers like this:
#ifdef LINK_WITH_LIBFOO #define weaklink_libfoo_init() 1 #elif defined(WEAKLINK_WITH_LIBFOO) /* generated from void foo_bar(int) */ extern void (*foo_bar)(int); /* initialize it to NULL in the .c file. */ void weaklink_libfoo_init(void); /* body of that function is { dlinit ...; foo_bar = dlsym ...; } */ #else /* they don't want to link with libfoo at all. */ #error Don't include this header unless HAVE_LIBFOO is defined. #endifAnd then do the appropriate configure-time trickery.