dlopen and detecting gnome



I'm trying to write a routine that'll try to figure out the users preferred 
web browser and launch it. So I've got a couple of Gnome questions:

1) The short question:
Is there any way I can reliably detect that the user is running a Gnome 
desktop?

2) The long question:
If I detect Gnome, I'd like to use gnome_url_show(). However, I don't want to 
make my app (it's a game) reliant on libgnome being present (or kde/other 
libs for that matter), so I thought I'd use dlopen() to dynamically get at 
gnome_url_show() at runtime.
However, I found that I _also_ need to dlopen() libgnomesupport or I get 
unresolved symbols when I open libgnome. I'd have thought that libgnome.so 
would list libgnomesupport.so among it's dependencies, but using ldd this 
doesn't seem to be the case... What is the intention?

In the end, I came up with the following code which works OK on my machine.
I'd appreciate any comments.

------------------------------------
#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( "libgnomesupport.so", RTLD_NOW|RTLD_GLOBAL );
    if( !gnomesupportlib )
    {
        printf("couldn't dlopen libgnomesupport.so: %s\n",dlerror() );
        return 1;
    }
    gnomelib = dlopen( "libgnome.so", RTLD_LAZY );

    if( !gnomelib )
    {
        printf("couldn't dlopen libgnome.so: %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( "http://www.gnome.org"; );

    dlclose( gnomelib );
    dlclose( gnomesupportlib );

    return 0;
}

------------------------------------
Ooop - I seem to omit calling gnome_init(), but it doesn't seem to affect it.


Thanks,
Ben.









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