[Glade-users] libglade - connecting signals
Dean Schumacher
dean.schumacher@usa.alcatel.com
Wed, 28 Feb 2001 13:58:33 -0600
I've got this working now!
The first problem was that I needed to add a linker flag to
export the internal symbols. On Linux, this is -rdynamic.
On Solaris it's -E.
Running "gnome-config --libs libglade" will give you the
correct flag on Linux, but not on Solaris. So I just added
it myself. Compiling with gcc (or g++), I just have to add
a -Wl,-E option.
Once I had that done, Libglade would successfully connect
signal handlers for C code.
Then, to get it working for C++, I followed your suggestion
of using the extern "C" block. For my simple test program,
that just meant doing the following. I just included this
as an example in case anyone else is having the same problem.
#include <string.h>
#include <gnome.h>
#include <glade/glade.h>
/* Use C linkage so that Libglade can dynamically connect the signal
handlers */
extern "C" {
/* all my code here */
} /* extern "C" */
Thanks for your help!
Regards,
Dean
Dean Schumacher wrote:
>
> Andrae,
>
> Thanks for the info. I was wondering whether this might have
> something to do with gmodule because I read something about
> that in the Libglade Reference Manual.
>
> However, the little sample program that I'm using is really
> just C code compiled with a C++ compiler because I was trying
> to demonstrate that I could use Libglade with C++. If I compile
> it with a C compiler I still have the same problem. So I'm
> left where I started.
>
> BTW, do you know where I could look to get some info on
> how to add C++ name-mangling support to gmodule? This
> doesn't sound very trivial.
>
> Regards,
> Dean
>
> Andrae Muys wrote:
> >
> > Dean Schumacher wrote:
> > >
> > > Hello.
> > >
> > > I've been trying to use Libglade to automatically connect signal
> > > handlers in my C++ code, but the glade_xml_signal_autoconnect
> > > function is not working.
> > >
> > > So I decided to try to connect the signal handlers manually
> > > using glade_xml_signal_connect (instead of autoconnect) as
> > > shown:
> > >
> > > glade_xml_signal_connect(xml, "on_about1_activate",
> > > GTK_SIGNAL_FUNC(on_about1_activate));
> > >
> > > This doesn't work either. I get no error message, but the
> > > signal handler isn't connected. Selecting the Help->About
> > > menu option does nothing, when it should be calling my
> > > signal handler to display a Help About window.
> > >
> > > Does anyone have any ideas on what could be wrong with my
> > > environment or what libraries might not be built with the
> > > correct support, or whatever. I have no idea where to look.
> > >
> > Ahhh I was going to reply to this the other day, but I ran out of time.
> >
> > I would guess that you are being caught out by C++'s name mangling.
> > libglade's introspection is based on gmodule, which is based on libdl.
> > This allows you to search the current processes symbol table for a given
> > symbol and extract the associated pointer reference. All very funky and
> > cool, and I'm using the same facilities in developing the plugin
> > infrastructure for Glade. However there is a problem, in that the
> > mapping between a C function and it's symbol is very simple (prepend a
> > _), whereas the name mangling for C++ is a awful mess.
> >
> > So effectively what this means is, you either have to add C++
> > name-mangling support to gmodule (and possibly libdl), or you can only
> > dynamically connect to functions using C linkage. It's been a while
> > since I did any C++ at all, however I believe you do this by enclosing
> > the signature (and function?) with extern "C" { ... } blocks.
> >
> > Anyway, I remember you still had a problem with the C code I sent you so
> > there maybe an additional problem unrelated to this.
> >
> > Andrae Muys
>
> Alcatel USA
>
> _______________________________________________
> Glade-users maillist - Glade-users@helixcode.com
> http://lists.helixcode.com/mailman/listinfo/glade-users
--
Dean Schumacher Email: dean.schumacher@usa.alcatel.com
Software Engineering Tools Phone: 972.519.3252
Alcatel USA