[SOLVED]Nmake compiles my project fine, but VS2010 IDE does not.
After running nmake (succesfully) to compile a small project, the output debug program runs as expected, but I constantly receive the following linker errors during compilation from within the IDE:
1>Notepad.obj : error LNK2001: unresolved external symbol “public: virtual struct QMetaObject const * __thiscall Notepad::metaObject(void)const “ (?metaObject@Notepad@@UBEPBUQMetaObject@@XZ)
1>Notepad.obj : error LNK2001: unresolved external symbol “public: virtual void * __thiscall Notepad::qt_metacast(char const *)” (?qt_metacast@Notepad@@UAEPAXPBD@Z)
1>Notepad.obj : error LNK2001: unresolved external symbol “public: virtual int __thiscall Notepad::qt_metacall(enum QMetaObject::Call,int,void * *)” (?qt_metacall@Notepad@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>Notepad.obj : error LNK2001: unresolved external symbol “public: static struct QMetaObject const Notepad::staticMetaObject” (?staticMetaObject@Notepad@@2UQMetaObject@@B)
Is there any additional steps required to be able to compile the project from within the VS2010 IDE?
Thanks! First Post! New to Qt!
Ok, it turns out that I needed to include the generated moc cpp’s with my VS2010 project as headers.
From my understanding, I only need to generate a moc file for each class that utilizes the Q_OBJECT macro once. Is this correct?
EDIT: Whenever you make modifications to your class(es) that is/are utilizing the Q_OBJECT macro, you will need to call nmake again to regenerate the moc file, as the moc file makes references to various qualities of your class. Hence, my previous guess is incorrect.
So I guess my question now, is, how do I automate this “nmake process” during compile time in VS2010? I now head out to find a solution on my own to report back.
Nmake can easily be executed as a pre-build event. Here is what I used:
echo “Pre-Build Event Initializing…”
echo “Pre-Build Event Complete”
Now, moc files will be generated from within the IDE just before compilation, and will then compile successfully during compilation. If you ever make changes to any classes utilizing the Q_OBJECT macro, the moc files will be updated accordingly when you compile your project.
Good luck to everyone!