I am using Visual Studio with qt addin and when I build my project, it generates moc_*.cpp files as a result of build rule in my project :
<Tool
Name="VCCustomBuildTool"
Description="Moc'ing $(InputFileName)..."
CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o .\GeneratedFiles\$(ConfigurationName)\moc_$(InputName).cpp (continues..)
AdditionalDependencies="$(QTDIR)\bin\moc.exe;.\myfilewithqobject.h"
Outputs=".\GeneratedFiles\$(ConfigurationName)\moc_myfilewithqobject.cpp"/>
After generating moc_myfilewithqobject.cpp, it continues to build project and in linking phase it gives LINK 2001 errors :
unresolved external symbol "public: virtual struct QMetaObject const * __thiscall myfilewithobject::metaObject(void)const
unresolved external symbol "public: virtual void * __thiscall myfilewithobject::qt_metacast(char const *)
unresolved external symbol "public: virtual int __thiscall myfilewithobject::qt_metacall
Because it cannot find the file moc_myfilewithobject.obj. moc_myfilewithobject.obj is not generated because moc_myfilewithobject.cpp is not compiled after generation. However when I include moc_myfilewithobject.cpp to my project,then it is compiled and the problem is solved. But this is done by hand and it sometimes causes some problems. Are there a way to solve this problem without including moc_.cpp files to project manually? Like compiling moc_.cpp after just generation or including it automatically?
Note : I added a trial .h file as a qt class for seeing what happens when new qt header added in project file. It added the lines that are not owned by my problematic file :
<ClCompile Include="GeneratedFiles\Debug\moc_Denemeqt.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
So it is a true configuration I think, but my file created before as a qt class does not have such a configuration. However when I delete Debug folder in GeneratedFiles it gives same errors because when I delete Debug folder the moc_.cpp files also deleted from project file. So here is the question : generated moc_.cpp files must not be deleted, is it true?