我在使用g ++进行编译时遇到了这个错误,我在网上搜索但是我无法找到答案。我试图修改它,但仍然是同样的错误。
/tmp/ccg3Y3r9.o: In function `main':
main.cc:(.text+0x6c): undefined reference to `examplewindow::examplewindow()'
main.cc:(.text+0x9e): undefined reference to `examplewindow::~examplewindow()'
main.cc:(.text+0x106): undefined reference to `examplewindow::~examplewindow()'
collect2: error: ld returned 1 exit status
这是我的代码
radio_buttons.h
#ifndef GTKMM_EXAMPLE_RADIOBUTTONS_H
#define GTKMM_EXAMPLE_RADIOBUTTONS_H
#include <gtkmm/box.h>
#include <gtkmm/window.h>
#include <gtkmm/radiobutton.h>
#include <gtkmm/separator.h>
class RadioButtons : public Gtk::Window
{
public:
RadioButtons();
virtual ~RadioButtons();
protected:
//Signal handlers:
void on_button_clicked();
//Child widgets:
Gtk::Box m_Box_Top, m_Box1, m_Box2;
Gtk::RadioButton m_RadioButton1, m_RadioButton2, m_RadioButton3;
Gtk::Separator m_Separator;
Gtk::Button m_Button_Close;
};
#endif //GTKMM_EXAMPLE_RADIOBUTTONS_H
radiobuttons.cc
#include "radio_buttons.h"
RadioButtons::RadioButtons() :
m_Box_Top(Gtk::ORIENTATION_VERTICAL),
m_Box1(Gtk::ORIENTATION_VERTICAL, 10),
m_Box2(Gtk::ORIENTATION_VERTICAL, 10),
m_RadioButton1("button1"),
m_RadioButton2("button2"),
m_RadioButton3("button3"),
m_Button_Close("close")
{
// Set title and border of the window
set_title("radio buttons");
set_border_width(0);
// Put radio buttons 2 and 3 in the same group as 1:
Gtk::RadioButton::Group group = m_RadioButton1.get_group();
m_RadioButton2.set_group(group);
m_RadioButton3.set_group(group);
// Add outer box to the window (because the window
// can only contain a single widget)
add(m_Box_Top);
//Put the inner boxes and the separator in the outer box:
m_Box_Top.pack_start(m_Box1);
m_Box_Top.pack_start(m_Separator);
m_Box_Top.pack_start(m_Box2);
// Set the inner boxes' borders
m_Box2.set_border_width(10);
m_Box1.set_border_width(10);
// Put the radio buttons in Box1:
m_Box1.pack_start(m_RadioButton1);
m_Box1.pack_start(m_RadioButton2);
m_Box1.pack_start(m_RadioButton3);
// Set the second button active
m_RadioButton2.set_active();
// Put Close button in Box2:
m_Box2.pack_start(m_Button_Close);
// Make the button the default widget
m_Button_Close.set_can_default();
m_Button_Close.grab_default();
// Connect the clicked signal of the button to
// RadioButtons::on_button_clicked()
m_Button_Close.signal_clicked().connect(sigc::mem_fun(*this,
&RadioButtons::on_button_clicked) );
// Show all children of the window
show_all_children();
}
RadioButtons::~RadioButtons()
{
}
void RadioButtons::on_button_clicked()
{
hide(); //to close the application.
}
main.cc
#include "radio_buttons.h"
#include <gtkmm/application.h>
int main(int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
RadioButtons buttons;
//Shows the window and returns when it is closed.
return app->run(buttons);
}
我在网上搜索答案,但由于我是初学者,我无法理解我在网上找到的答案。我在这里。