libgnome and dlopen()

Is it reasonable to use dlopen() to dynamically access functions in libgnome?

I want to call gnome_url_show(), but I don't want to rely on the user having 
the gnome libraries installed.

I have got it working, abeit with some oddities - I have to dlopen() 
libgnomesupport and resolve all its symbols first before libgnome will work. 
'ldd' doesn't list libgnomesupport among the libgnome dependencies. Is this 
the desired behaviour, or unexpected wierdness?

The following code seems to work OK for me. Comments welcome :-)

#include <stdio.h>
#include <dlfcn.h>

int main( int argc, char* argv[] )

    void *gnomesupportlib;
    void *gnomelib;
    void *(*gnome_url_show)( const char *url );
    const char *err;

    gnomesupportlib = dlopen( "", RTLD_NOW|RTLD_GLOBAL );
    if( !gnomesupportlib )
        printf("couldn't dlopen %s\n",dlerror() );
        return 1;
    gnomelib = dlopen( "", RTLD_LAZY );

    if( !gnomelib )
        printf("couldn't dlopen %s\n",dlerror() );
        return 1;

    gnome_url_show = dlsym( gnomelib, "gnome_url_show" );
    err = dlerror();
    if( err )
        printf("couldn't find gnome_url_show(): %s\n", err );
        return 1;

    gnome_url_show( ""; );

    dlclose( gnomelib );
    dlclose( gnomesupportlib );

    return 0;


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