PDA

View Full Version : Unable to compile an Example



learner
15th November 2010, 07:50
Hi,
I am attempting to compile a first example project "MoveBlocks" and facing a problem with compilation. The compiler cannot find the "main.moc" file which is included at the end of the source file "main.cpp"

Here is the compiler output:
Running build steps for project moveblocks...
Configuration unchanged, skipping qmake step.
Starting: "D:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

D:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug all

mingw32-make[1]: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\include\QtCore" -I"..\..\..\include\QtGui" -I"..\..\..\include" -I"..\..\..\include\ActiveQt" -I"tmp\moc\debug_shared" -I"..\moveblocks" -I"." -I"..\..\..\mkspecs\win32-g++" -o tmp\obj\debug_shared\main.o ..\moveblocks\main.cpp

mingw32-make[1]: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

mingw32-make: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

..\moveblocks\main.cpp:319:20: error: main.moc: No such file or directory

mingw32-make[1]: *** [tmp/obj/debug_shared/main.o] Error 1

mingw32-make: *** [debug-all] Error 2

The process "D:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project moveblocks (target: Desktop)
When executing build step 'Make'

I am using Qt Creator 2.0.1 based on Qt 4.7.0 (32 bit) on WinXP
Will appreciate all help.

tbscope
15th November 2010, 10:00
Configuration unchanged, skipping qmake step.

Oops, this happens from time to time, especially if you do not change the .pro file.
This means the main.cpp file doesn't get processed by qmake resulting in a Makefile not calling the meta object compiler. This results in no .moc file being generated.

Solution: Clean the project and rebuild.

learner
15th November 2010, 10:11
tbscope,
Thanks for your prompt reply BUT the problem still persists. I did the "clean", i even deliberately changed and saved the source file so make will compile it. It did, but the same problem still persists.

Running build steps for project moveblocks...
Starting: "D:/Qt/2010.05/mingw/bin/mingw32-make.exe" clean -w
mingw32-make: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

D:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug clean

mingw32-make[1]: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

del tmp\moc\debug_shared\main.moc

del tmp\obj\debug_shared\main.o

mingw32-make[1]: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

D:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Release clean

Could Not Find D:\Qt\2010.05\qt\examples\animation\moveblocks-build-desktop\tmp\moc\debug_shared\main.moc

Could Not Find D:\Qt\2010.05\qt\examples\animation\moveblocks-build-desktop\tmp\obj\debug_shared\main.o

mingw32-make[1]: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

del tmp\moc\release_shared\main.moc

del tmp\obj\release_shared\main.o

mingw32-make[1]: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

mingw32-make: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

Could Not Find D:\Qt\2010.05\qt\examples\animation\moveblocks-build-desktop\tmp\moc\release_shared\main.moc

Could Not Find D:\Qt\2010.05\qt\examples\animation\moveblocks-build-desktop\tmp\obj\release_shared\main.o

The process "D:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited normally.
Configuration unchanged, skipping qmake step.
Starting: "D:/Qt/2010.05/mingw/bin/mingw32-make.exe" -w
mingw32-make: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

D:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug all

mingw32-make[1]: Entering directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\include\QtCore" -I"..\..\..\include\QtGui" -I"..\..\..\include" -I"..\..\..\include\ActiveQt" -I"tmp\moc\debug_shared" -I"..\moveblocks" -I"." -I"..\..\..\mkspecs\win32-g++" -o tmp\obj\debug_shared\main.o ..\moveblocks\main.cpp

mingw32-make[1]: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

mingw32-make: Leaving directory `D:/Qt/2010.05/qt/examples/animation/moveblocks-build-desktop'

..\moveblocks\main.cpp:319:20: error: main.moc: No such file or directory

mingw32-make[1]: *** [tmp/obj/debug_shared/main.o] Error 1

mingw32-make: *** [debug-all] Error 2

The process "D:/Qt/2010.05/mingw/bin/mingw32-make.exe" exited with code %2.
Error while building project moveblocks (target: Desktop)
When executing build step 'Make'

pan
15th November 2010, 10:20
add this to the moveblocks.pro

INCLUDEPATH += tmp/moc/release_shared

tbscope
15th November 2010, 10:25
Remove the Makefile, by hand if necessary.

A tip:
Try to build your code in a separate folder, a build folder. Then you can just remove the folder and create it again. This is the only way to be sure your software actually builds.

Edit: actually Qt Creator already builds in a separate folder.
You can just remove the moveblocks-build-desktop folder.

learner
15th November 2010, 14:27
This worked! Thanks.
Can you briefly explain why this is required? I do not see any reference for the DEBUG configuration in environment settings.

To clarify my question - In Project settings, there is no place where we can specify any directories like you suggested for the release one.

Another thing - in "Project" under "Run Settings" tab, I still see that executable for the release version is listed as being created in the debug directory, and this field is read-only. I suppose we should be able to change that to release - but how?

pan
15th November 2010, 14:54
I noticed this error:

..\moveblocks\main.cpp:319:20: error: main.moc: No such file or directory
Saw that your main.cpp used #include "main.moc"
so you just needed the path to the file to be added to the includepath list.

Alternatively, you probably could have moved the main.moc file into same directory as your source files... but I haven't looked at this project in detail, to know what could break as a result of that.

tbscope
15th November 2010, 14:58
so you just needed the path to the file to be added to the includepath list.

That would be a possible solution if the file was actually generated.
However, that was not the case as you can see in the compiler output that.
1. qmake decided not to update the Makefile
2. only one file got compiled, main.cpp

learner
15th November 2010, 15:09
I was just using one of the examples provided by Qt "as is" - which had the included main.moc at the end. In fact all of their sample examples have the same format. Maybe you have been with this long enough when this was not so.

pan
15th November 2010, 15:13
The file actually does exist along side the example code. In the directory I mentioned.
I assume only one file was compiled because it didn't know the location of the second.

tbscope
15th November 2010, 15:22
The qt examples do not contain .moc files. They are generated files.
If they do, it's a packaging bug.

learner
15th November 2010, 15:27
tbscope, yes thanks for your explanation on how these moc files get generated - your explanatory text seems to be gone - but I did read it. Thanks.