I wrote a class inherited from wxDialog. I’m currently on Ubuntu 12.04, using Code::Blocks with gcc 4.6. My application works fine until I include this class in the project: either the debug and release configuration give the same error. Here’s the code:
Header file
#ifndef EBCDIALOG_H
#define EBCDIALOG_H
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>
#include <wx/button.h>
class EBCDialog : public wxDialog
{
public:
EBCDialog(wxWindow* parent, wxWindowID id, const wxString& title );
~EBCDialog();
void OnOK(wxCommandEvent& event);
private:
DECLARE_CLASS(EBCDialog)
DECLARE_EVENT_TABLE()
};
#endif //EBCDIALOG_H
Cpp file:
#include "EBCDialog.h"
EBCDialog::EBCDialog(wxWindow* parent, wxWindowID id, const wxString& title ) : wxDialog(parent, id, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
// Create text ctrl with minimal size 100x60
topSizer->Add(new wxTextCtrl(this, wxID_ANY, wxT("test"), wxDefaultPosition, wxSize(100,60)),
1, // make vertically stretchable
wxEXPAND| // make horizontally stretchable
wxALL, // and make border all around
10); // set border width to 10
wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
buttonSizer->Add(new wxButton(this, wxID_OK, _T("OK")),
0, // make horizontally unstretchable
wxALL, // make border all around: implicit top alignment
10); // set border width to 10
buttonSizer->Add(new wxButton(this, wxID_CANCEL, _T("Cancel")),
0, // make horizontally unstretchable
wxALL, // make border all around (implicit top alignment)
10); // set border width to 10
topSizer->Add(buttonSizer,
0, // make vertically unstretchable
wxALIGN_CENTER ); // no border and centre horizontally
SetSizer( topSizer ); // use the sizer for layout
topSizer->Fit( this );
// fit the dialog to the contents
topSizer->SetSizeHints( this ); // set hints to honor min size
}
EBCDialog::~EBCDialog()
{
}
void EBCDialog::OnOK(wxCommandEvent& event)
{
}
BEGIN_EVENT_TABLE(EBCDialog, wxDialog)
EVT_BUTTON(wxID_OK, EBCDialog::OnOK)
END_EVENT_TABLE()
Here’s Code::Blocks log:
g++ -Wall -I/usr/lib/i386-linux-gnu/wx/include/gtk2-unicode-debug-2.8
-I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_WXDEBUG_ -D_WXGTK_ -pthread -O2 -I”/home/angelo/CodeBlocks/Event Bus Configurer/include” -I”/home/angelo/CodeBlocks/Event Bus Configurer/bitmaps” -c “/home/angelo/CodeBlocks/Event Bus Configurer/src/EBCDialog.cpp” -o
obj/src/EBCDialog.o g++ -o “bin/Event Bus Configurer” obj/src/EBCApp.o
obj/src/EBCDialog.o obj/src/EBCFrame.o obj/src/EBCList.o
obj/src/HandlerFile.o -L/usr/lib/i386-linux-gnu -pthread
-Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/i386-linux-gnu -lwx_gtk2ud_richtext-2.8 -lwx_gtk2ud_aui-2.8 -lwx_gtk2ud_xrc-2.8 -lwx_gtk2ud_qa-2.8 -lwx_gtk2ud_html-2.8 -lwx_gtk2ud_adv-2.8 -lwx_gtk2ud_core-2.8 -lwx_baseud_xml-2.8 -lwx_baseud_net-2.8 -lwx_baseud-2.8 -s obj/src/EBCDialog.o:(.rodata._ZTV9EBCDialog[vtable for EBCDialog]+0x8): undefined reference to `EBCDialog::GetClassInfo()
const’ collect2: ld returned 1 exit status Process terminated with
status 1 (0 minutes, 2 seconds) 1 errors, 0 warnings
Any help is appreciated, thank you!
remove DECLARE_CLASS(EBCDialog) from your code, the base class wxDialog already does that for you.
From the documentation: