Evan Martin (evan) wrote in evan_tech,
Evan Martin
evan
evan_tech

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.
Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments