evan_tech

Previous Entry Share Next Entry
08:41 am, 18 Feb 04

weak-linking

More demands for weak linking.
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.

#endif
And then do the appropriate configure-time trickery.