[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [mechglue] Static Linking - Circular Dependency



On Tue, Apr 25, 2006 at 02:59:07PM -0400, Michael B Allen wrote:

> To statically link however I modified mechglue/g_initialize.c to call
> gss_spnego_initialize call immediately after the gss_krb5_initialize
> call and commented out the gss_dynamic_initialize call. Then I added
> a libgssapi dependency on libmech_spnego and somehow managed to do
> things in the right sequence to actually build cleanly. I guess somehow
> I managed to recreate the libgssapi.la file without rebuilding the whole
> thing. But now I can't reproduce the process.

An other trick that can be used to avoid circular dependency is to use
static constructors. It's less portable (I know it works with GCC, I
don't know about any other compilers), but it is actually much nicer
because it removes the difference between static and dynamic linking.

The trick is:
- remove any mech-specific initialization calls from libgssapi
- add a static function to the mech libraries that is marked with
  __attribute__((__constructor__)). This function should initialize the
  mech library and register it with libgssapi (I haven't looked at the
  mechglue code so I'm not sure of the details)

After that if you link an application against a mech library (e.g.
-lmech_spnego -lgssapi), then that mechanism will be available
regardless if libmech_spnego is built as a static or as a dynamic
library.

I've used this trick with gLite service discovery plugin implementations
and it worked very well. But I only had to care about Linux as the
target platform so portability was not an issue.

Gabor

-- 
     ---------------------------------------------------------
     MTA SZTAKI Computer and Automation Research Institute
                Hungarian Academy of Sciences
     ---------------------------------------------------------