[Glade-users] libglade - connecting signals

Andrae Muys amuys@shortech.com.au
Wed, 28 Feb 2001 09:38:27 +1000


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