-   Programming (
-   -   GTKmm and SigC (

stonehurstX11 05-04-2005 01:08 AM

GTKmm and SigC
I just started learning GTKmm (using Qt right now; just trying this toolkit out ;) ), and I ran into some problems. I tried to compile the example from's tutorial, but apparently there is something going on with sigc++ 2.0. I'm using Mandrake 10.1 and installed all the appropriate libsigc++ libraries, including the development ones.

Here is the problem. Take this code for example:

Gtk::Button m_button1("Quit");
m_button1.signal_clicked().connect( sigc::mem_fun(*this, &HelloWorld::on_button_clicked) );

g++ complained that 'sigc' was undeclared, so I Googled around and found out that changing sigc to SigC should work, which it did. But now for some reason, the compiler complains that 'mem_fun' is not a member of SigC.

Any ideas on how to fix this? Thanks in advance!

deiussum 05-04-2005 09:36 AM

I'm just starting to use GTKmm a bit myself, but the code as you listed it should be the correct way to call sigc::mem_fun. Do you have the right headers included? Was the original error a compiler error or linker error? Perhaps you forgot to include the sigc library? Did you use pkg-config to get the cflags and libs?

(e.g. g++ -o file somefile.cpp `pkg-config gtkmm-2.4 --libs --cflags`)

stonehurstX11 05-04-2005 02:39 PM

I've got the sigc++ 2.0 library and I'm using a compile command similar to yours including the pkconfig bit. The original error was a compile error. This is the output from g++ after I attempt to compile a sample file:


g++ hello.cpp -o hello `pkg-config gtkmm-2.0 --cflags --libs`
hello.cpp: In function `int main(int, char**)':
hello.cpp:18: error: `sigc' has not been declared
hello.cpp:18: error: `mem_fun' undeclared (first use this function)
hello.cpp:18: error: (Each undeclared identifier is reported only once for each function it appears in.)

This is how the hello.cpp file looks like:

#include <gtkmm.h>
#include <iostream>

void slot_x() {
        std::cout << "hello world!\n";

int main(int argc, char *argv[]) {
        Gtk::Main app(argc, argv);

        Gtk::Button b("Test");
        b.signal_clicked().connect(sigc::mem_fun(b, slot_x));       
        Gtk::Window mw;


        return 0;

As for the headers, I'm not too sure which needs to be included, so I tried sigc++.h but that didn't seem to work. I also tried older versions of sigc++, such as 1.2, but that made no difference.

deiussum 05-04-2005 03:03 PM

I get a different error when trying to compile your code:


$ g++ -o hello hello.cpp `pkg-config gtkmm-2.4 --cflags --libs`
hello.cpp: In function `int main(int, char**)':
hello.cpp:12: error: no matching function for call to `mem_fun(Gtk::Button&,
  void (&)())'

The reason for the error is that sigc::mem_fun is meant to create a functor for class member functions, and you are trying to create a functor to a global function. Use the following instead:


But, that still may not take care of your problem because it's not finding sigc for some reason...

What is the output of pkgconfig gtkmm-2.0 --cflags?

Mine is as follows:

$ pkg-config gtkmm-2.4 --cflags
-I/usr/local/include/gtkmm-2.4 -I/usr/local/lib/gtkmm-2.4/include -I/usr/local/i
nclude/glibmm-2.4 -I/usr/local/lib/glibmm-2.4/include -I/usr/local/include/gdkmm
-2.4 -I/usr/local/lib/gdkmm-2.4/include -I/usr/local/include/pangomm-1.4 -I/usr/
local/include/atkmm-1.6 -I/usr/include/gtk-2.0 -I/usr/local/include/sigc++-2.0 -
I/usr/local/lib/sigc++-2.0/include -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/i
nclude -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/X11R6/include
-I/usr/include/freetype2 -I/usr/include/atk-1.0

The only other difference that I see is that you appear to be using gtkmm-2.0 while I'm using gtkmm-2.4....

stonehurstX11 05-04-2005 03:17 PM

Apparently, I upgraded to gtkmm-2.4 and that solved everything. :) I also changed mem_fun to ptr_fun like you said and that took care of the compile error. Thanks for all the help!

All times are GMT -5. The time now is 06:09 PM.