PDA

View Full Version : Why do I still get LNK 2001 error when I have defined the QWT_DLL preprocessor???



accordionist
15th November 2010, 00:45
I defined a class inherited from QDialog, the class has a QwtPlot, when I compile the project, LNK 2001 error occured:

griddatadialog.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall GridDataDialog::metaObject(void)const " (?metaObject@GridDataDialog@@UBEPBUQMetaObject@@XZ )
1>griddatadialog.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall GridDataDialog::qt_metacast(char const *)" (?qt_metacast@GridDataDialog@@UAEPAXPBD@Z)
1>griddatadialog.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall GridDataDialog::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@GridDataDialog@@UAEHW4Call@QMetaObje ct@@HPAPAX@Z)
1>griddatadialog.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const GridDataDialog::staticMetaObject" (?staticMetaObject@GridDataDialog@@2UQMetaObject@@ B)


if I comment out the Q_OBJECT macro, no link error occured, but I can't use the buttons and combobox in the dialog, I've defined the QWT_DLL preprocessor, does anyone know how to solve this problem??Thanks a lot.

Added after 5 minutes:

Forget to say, I use Visual Studio 2005, and compile both the QWT source code and my own project in debug mode. How does the error occur???

ChrisW67
15th November 2010, 03:04
Are the qwt libraries in the LIBS variable of your PRO file? For example:


QWTPATH = C:/Qwt-5.2.1
INCLUDEPATH += $$QWTPATH/include
LIBS += -L$$QWTPATH/lib -lqwt5

accordionist
15th November 2010, 06:12
I' ve solved the problem myself!! My Visual Studio doesn't generate the moc_XXX.cpp file automatically. Open Visual Studio, right click the .h file, select properties, Custom Build Step, Command Line Step, input "%qtdir%\bin\moc.exe" "$(InputDir)$(InputName).h" -o "ui\moc_$(InputName).cpp", then build the project, and then add the generated moc_XXX.cpp file to the project, the errors disappear!

FelixB
15th November 2010, 07:53
If you have the VisualStudio Qt-AddIn installed, you can create a Qt-Project instead of a console-application. Then these generating-steps will be performed automatically :)