LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2005, 12:08 AM   #1
stonehurstX11
Member
 
Registered: Dec 2003
Location: New Jersey, USA
Posts: 120

Rep: Reputation: 15
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 gtkmm.org'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:
Code:
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!
 
Old 05-04-2005, 08:36 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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`)

Last edited by deiussum; 05-04-2005 at 08:38 AM.
 
Old 05-04-2005, 01:39 PM   #3
stonehurstX11
Member
 
Registered: Dec 2003
Location: New Jersey, USA
Posts: 120

Original Poster
Rep: Reputation: 15
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:

Code:
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:
Code:
#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;

	mw.add(b);
	mw.show();
	b.show();

	Gtk::Main::run(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.
 
Old 05-04-2005, 02:03 PM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

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

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:

Code:
b.signal_clicked().connect(sigc::ptr_fun(slot_x));
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:
Code:
$ 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....
 
Old 05-04-2005, 02:17 PM   #5
stonehurstX11
Member
 
Registered: Dec 2003
Location: New Jersey, USA
Posts: 120

Original Poster
Rep: Reputation: 15
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sigc.dll not found fatrandy13 Linux - Software 1 04-02-2005 01:47 PM
gtkmm help paulr1984 Linux - Software 1 03-28-2005 02:40 AM
Problems compiling sigc++ programs siminone Programming 4 10-24-2004 06:31 PM
sigc++-2.0 paul62 Linux - Software 0 10-01-2004 10:51 AM
gtkmm HOW? Barq Programming 1 08-29-2004 07:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration