undefined reference to vtable

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
mastupristi
Knows some wx things
Knows some wx things
Posts: 28
Joined: Tue Oct 18, 2005 7:52 am

undefined reference to vtable

Post by mastupristi » Tue Oct 25, 2005 5:51 am

I use wxDev-Cpp beta 6.8 (with mingw 3.4 and wxwidgets 2.6.1)
I have defined a derived Class of wxComboBox, and I obtain a linker error:

undefined reference to `vtable for MyComboBox'

How can avoid this problem?

thanks

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Tue Oct 25, 2005 6:37 am

if you called DECLARE_EVENT_TABLE() in MyComboBox, make sure you defined an event table for MyComboBox

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Tue Oct 25, 2005 6:40 am

It helps by showing some (stripped down) code. Remember, even pragma's can cause this. Are you using the #pragma implementation part by any chance?

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

mastupristi
Knows some wx things
Knows some wx things
Posts: 28
Joined: Tue Oct 18, 2005 7:52 am

Post by mastupristi » Tue Oct 25, 2005 6:48 am

lowjoel wrote:if you called DECLARE_EVENT_TABLE() in MyComboBox, make sure you defined an event table for MyComboBox
Here is my header file:

Code: Select all

#ifndef MYCOMBOBOX_H
#define MYCOMBOBOX_H

#include <wx/combobox.h> // inheriting class's header file

/*
 * No description
 */
class MyComboBox : public wxComboBox
{
	public:
		// class constructor
        MyComboBox(wxWindow* parent, wxWindowID id, 
               const wxString& value, 
               const wxPoint& pos, 
               const wxSize& size, 
               const wxArrayString& choices = NULL, 
               long style = 0, 
               const wxValidator& validator = wxDefaultValidator, 
               const wxString& name = wxComboBoxNameStr)
        : wxComboBox(parent, id, value, pos, size, choices, style,
                     validator, name) { };

		// class destructor
		~MyComboBox();
protected:
    void OnFocusGot(wxFocusEvent& event);
private:
    DECLARE_EVENT_TABLE();
};

#endif // MYCOMBOBOX_H
and the cpp:

Code: Select all

#include "mycombobox.h" // class's header file

BEGIN_EVENT_TABLE(MyComboBox, wxComboBox)
    EVT_SET_FOCUS(MyComboBox::OnFocusGot)
END_EVENT_TABLE()

void MyComboBox::OnFocusGot(wxFocusEvent& event)
{
	// insert your code here
}
and I use this command to link:

Code: Select all

g++.exe vsendppDlg.o vsendppApp.o mycombobox.o vsendpp_private.res -o "vsendpp.exe" -L"C:/Dev-Cpp/lib" -mwindows -lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lopengl32  
Is that correct? Have I defined correctly the event table?

thanks
Last edited by mastupristi on Tue Oct 25, 2005 7:13 am, edited 1 time in total.

mastupristi
Knows some wx things
Knows some wx things
Posts: 28
Joined: Tue Oct 18, 2005 7:52 am

Post by mastupristi » Tue Oct 25, 2005 6:51 am

Jorg wrote:It helps by showing some (stripped down) code. Remember, even pragma's can cause this. Are you using the #pragma implementation part by any chance?
I don't think (if wxDev-Cpp hasn't add it).

thanks

waterj
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

Post by waterj » Mon Jan 16, 2006 6:38 am

mastupristi wrote:
Jorg wrote:It helps by showing some (stripped down) code. Remember, even pragma's can cause this. Are you using the #pragma implementation part by any chance?
I don't think (if wxDev-Cpp hasn't add it).

thanks
I think your'd better check for something like "#pragma interface" in your code.

DavidHart
Site Admin
Site Admin
Posts: 4045
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Mon Jan 16, 2006 12:42 pm

Maybe you just didn't post the code, but the destructor is declared but not defined. If so, that would give the error message.

If that's not it, 2 other suggestions. Remove the unnecessary semi-colons after the constructor and after DECLARE_EVENT_TABLE(). This doesn't cause the error for me using linux, but maybe in your setup . . . . .

Failing that, remove everything :wink: . Try just class MyComboBox : public wxComboBox{}; If that still fails, you'll know it's not your code. If it works, add things back one by one until the error recurs.

HTH,

David

jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

Post by jazz » Tue Jan 17, 2006 1:35 am

DavidHart wrote:Maybe you just didn't post the code, but the destructor is declared but not defined. If so, that would give the error message.
That'd be it. I get that compile error all the time cause I declare a destructor out of habit but then forget to define it if I don't need it.
[INSERT LAME SIG HERE]

Post Reply