Q
Quansheng Liang
Hello,
I struggled with the problem of "undefined reference to `vtable ...`"
while migrating a project from windows to linux. After searching the
google I removed all the inline functions and now the link errors
decreased from over 200 to 5. A great step!
But one of my class derived from wxValidator can't be linked correctly
though there is no any inline function in it.
The error message:
-----------------------
Linking...
/home/qsliang/projects/ezData/Debug/validator.o(.text+0x19): In
function `ezValidatorLong::ezValidatorLong[not-in-charge](long*)':
/usr/local/include/wx/string.h:717: undefined reference to `vtable for
ezValidatorLong'
/home/qsliang/projects/ezData/Debug/validator.o(.text+0x55): In
function `ezValidatorLong::ezValidatorLong[in-charge](long*)':
src/helper/validator.cpp:22: undefined reference to `vtable for
ezValidatorLong'
/home/qsliang/projects/ezData/Debug/validator.o(.text+0x91): In
function `ezValidatorLong::ezValidatorLong[not-in-charge](long*, long,
long)':
src/helper/validator.cpp:27: undefined reference to `vtable for
ezValidatorLong'
/home/qsliang/projects/ezData/Debug/validator.o(.text+0xcb): In
function `ezValidatorLong::ezValidatorLong[in-charge](long*, long,
long)':
src/helper/validator.cpp:27: undefined reference to `vtable for
ezValidatorLong'
My class (in two files):
------------------------
class ezValidatorLong : public wxValidator
{
private:
long *mpValue, mMin, mMax;
public:
ezValidatorLong(long *pValue);
ezValidatorLong(long *pValue, long xMin, long xMax);
// ~ezValidatorLong();
wxObject* Clone() const;
bool Validate(wxWindow* pParent);
bool TransferFromWindow();
bool TransferToWindow();
};
ezValidatorLong::ezValidatorLong(long *pValue)
{ mpValue = pValue;
mMin = 1;
mMax = 0;
}
ezValidatorLong::ezValidatorLong(long *pValue, long xMin, long xMax)
{ mpValue = pValue;
mMin = xMin;
mMax = xMax;
}
//ezValidatorLong::~ezValidatorLong(){}
wxObject* ezValidatorLong::Clone() const
{ return new ezValidatorLong(mpValue,mMin,mMax);
}
bool ezValidatorLong::Validate(wxWindow*)
{ return // do-check //;
}
bool ezValidatorLong::TransferFromWindow()
{ wxString s = ((wxTextCtrl*)GetWindow())->GetValue();
s.ToLong(mpValue);
return true;
}
bool ezValidatorLong::TransferToWindow()
{ wxString s;
s.Printf("%ld",*mpValue);
((wxTextCtrl*)GetWindow())->SetValue(s);
return true;
}
--------------------------
The destructor, Clone(), Validate(), Transfer..Window() in wxValidator
are virtual. In my class, I got the same result no matter if there is
a destructor.
In the project, wxValidator is also used directly muliple times
without problem.
Any suggestion will be highly appreciated!
Liang
I struggled with the problem of "undefined reference to `vtable ...`"
while migrating a project from windows to linux. After searching the
google I removed all the inline functions and now the link errors
decreased from over 200 to 5. A great step!
But one of my class derived from wxValidator can't be linked correctly
though there is no any inline function in it.
The error message:
-----------------------
Linking...
/home/qsliang/projects/ezData/Debug/validator.o(.text+0x19): In
function `ezValidatorLong::ezValidatorLong[not-in-charge](long*)':
/usr/local/include/wx/string.h:717: undefined reference to `vtable for
ezValidatorLong'
/home/qsliang/projects/ezData/Debug/validator.o(.text+0x55): In
function `ezValidatorLong::ezValidatorLong[in-charge](long*)':
src/helper/validator.cpp:22: undefined reference to `vtable for
ezValidatorLong'
/home/qsliang/projects/ezData/Debug/validator.o(.text+0x91): In
function `ezValidatorLong::ezValidatorLong[not-in-charge](long*, long,
long)':
src/helper/validator.cpp:27: undefined reference to `vtable for
ezValidatorLong'
/home/qsliang/projects/ezData/Debug/validator.o(.text+0xcb): In
function `ezValidatorLong::ezValidatorLong[in-charge](long*, long,
long)':
src/helper/validator.cpp:27: undefined reference to `vtable for
ezValidatorLong'
My class (in two files):
------------------------
class ezValidatorLong : public wxValidator
{
private:
long *mpValue, mMin, mMax;
public:
ezValidatorLong(long *pValue);
ezValidatorLong(long *pValue, long xMin, long xMax);
// ~ezValidatorLong();
wxObject* Clone() const;
bool Validate(wxWindow* pParent);
bool TransferFromWindow();
bool TransferToWindow();
};
ezValidatorLong::ezValidatorLong(long *pValue)
{ mpValue = pValue;
mMin = 1;
mMax = 0;
}
ezValidatorLong::ezValidatorLong(long *pValue, long xMin, long xMax)
{ mpValue = pValue;
mMin = xMin;
mMax = xMax;
}
//ezValidatorLong::~ezValidatorLong(){}
wxObject* ezValidatorLong::Clone() const
{ return new ezValidatorLong(mpValue,mMin,mMax);
}
bool ezValidatorLong::Validate(wxWindow*)
{ return // do-check //;
}
bool ezValidatorLong::TransferFromWindow()
{ wxString s = ((wxTextCtrl*)GetWindow())->GetValue();
s.ToLong(mpValue);
return true;
}
bool ezValidatorLong::TransferToWindow()
{ wxString s;
s.Printf("%ld",*mpValue);
((wxTextCtrl*)GetWindow())->SetValue(s);
return true;
}
--------------------------
The destructor, Clone(), Validate(), Transfer..Window() in wxValidator
are virtual. In my class, I got the same result no matter if there is
a destructor.
In the project, wxValidator is also used directly muliple times
without problem.
Any suggestion will be highly appreciated!
Liang