I'm practicing with gtk (or gtkmm in this case), to which I'm completely new and I'm relatively new to c++. I got a working program that could open a window and put a few widgets in it, but now I'm trying to add an action to a button, and it just won't work.
main.cc:
#include <iostream>
#include "buttons.h"
#include <gtkmm/application.h>
void printLine()
{
std::cout<<"you pressed the button"<<std::endl;
}
int main(int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app =
Gtk::Application::create(argc, argv,
"org.gtkmm.examples.base");
Buttons buttons;
return app->run(buttons);
}
buttons.h:
#ifndef GTKMM_EXAMPLE_BUTTONS_H
#define GTKMM_EXAMPLE_BUTTONS_H
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/box.h>
class Buttons : public Gtk::Window
{
public:
Buttons();
virtual ~Buttons();
protected:
//Signal handlers:
void on_button_clicked();
//Child widgets:
Gtk::Button m_button;
Gtk::Box buttonBox;
};
#endif //GTKMM_EXAMPLE_BUTTONS_H
buttons.cc:
#include <iostream>
#include "buttons.h"
Buttons::Buttons()
{
m_button.add_pixlabel("info.xpm", "click here");
set_title("Pixmap'd buttons!");
set_border_width(10);
m_button.signal_clicked().connect( sigc::mem_fun(*this,
&Buttons::on_button_clicked) );
add(buttonBox);
buttonBox.pack_start(m_button);
//m_button.show();
show_all_children();
}
Buttons::~Buttons()
{
}
void Buttons::on_button_clicked()
{
printLine();
}
I am using g++ to compile the program and it gives me this error message:
g++ main.cc -o button pkg-config gtkmm-3.0 --cflags --libs
/tmp/ccKyphYe.o: In function main':
main.cc:(.text+0x93): undefined reference to
Buttons::Buttons()'
main.cc:(.text+0xc5): undefined reference to Buttons::~Buttons()'
main.cc:(.text+0x124): undefined reference to
Buttons::~Buttons()'
collect2: error: ld returned 1 exit status