Author Topic: Can't compile qt4 projects when using custom makefiles  (Read 14827 times)

Offline JHAx86

  • Single posting newcomer
  • *
  • Posts: 7
Can't compile qt4 projects when using custom makefiles
« on: September 28, 2008, 12:53:25 am »
Hello,

First of all let me say that the single file samples from trolltech compile right. The problem happens when trying to compile applications like the MDI Example that uses the Q_OBJECT macro. These projects require a proper moc handling. To simplify that task trolltech provides qmake.

As qmake introduction says, complex projects will fail at linking time if you do not provide a qmake generated Makefile. My problem is to use that makefile in my code blocks project.

To generate the Makefile I did the following:

1- Add qmake directory to path environment variable, this way I can type qmake everywhere without type the full path.
2- Use Notepad to create a pro file for my project and save it to my project cbp directory.
3- Go to my project directory and type "qmake -o Makefile myproject.pro". This way Makefile.Release and Makefile.Debug are generated in my project dir.
4- Run Code Blocks and configure projects properties to use a custom Makefile. Please, note that all qt includes,lib and base dirs are correctly configured as I able to compile and run samples like "Family Values", by copying the code from the tutorial web page and paste it in my cb project.

My problem started here. When you mark the "This is a custom makefile" in the project properties page. The Make Commands in the project build options page Make Commands tab are used. But, as I have others compilers installed, the $make variable points to Borland Make, and this says that don't know how to handle some things in make file. So, to force the use of mingw make, I replaced $make for mingw32-make, this way mingw make is used but then this returns errors. First It says "no rule defined for cleanRelease and cleanDebug". So I leave blank the make commands "Clean project/target:" and "Dist-clean project/target". But now, again, appears a lot of errors such as:

main.cpp|1|QApplication: No such file or directory|
mainwindow.h|4|QMainWindow: No such file or directory|

This looks like the includes between <> like <QApplication> cannot be correctly resolved. I insist, my qt path is correctly configured as I able to compile and run the simplest samples without use a custom makefile. But samples such the MDI application, requiring a qmake made Makefile, fail.

¿What's the correct CB configuration to successfully use a qmake made Makefile?

Thanks for read.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Can't compile qt4 projects when using custom makefiles
« Reply #1 on: September 28, 2008, 05:36:35 am »
Did you get the makefile to work outside of Code::Blocks?

If not, I suggest trying that to confirm the makefile works.

Tim s
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline JHAx86

  • Single posting newcomer
  • *
  • Posts: 7
Re: Can't compile qt4 projects when using custom makefiles
« Reply #2 on: September 28, 2008, 04:34:30 pm »
It looks like it is not working,

myprojectdir\>qmake -o Makefile myproject.pro

D:\Proyectos\myproject\Levedit>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `D:/Proyectos/myproject/Levedit'
g++ -c -O2 -Wall -fno-exceptions -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT
_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\
iwmake\build_mingw_opensource\include\QtCore" -I"c:\iwmake\build_mingw_opensourc
e\include\QtGui" -I"c:\iwmake\build_mingw_opensource\include" -I"." -I"c:\iwmake
\build_mingw_opensource\include\ActiveQt" -I"release" -I"." -I"..\..\Libraries\C
PP\Mingw\Qt\4.4.2\mkspecs\win32-g++" -o release\main.o main.cpp
main.cpp:1:24: QApplication: No such file or directory
In file included from main.cpp:2:
mainwindow.h:4:23: QMainWindow: No such file or directory
In file included from main.cpp:2:
mainwindow.h:20: error: expected class-name before '{' token
mainwindow.h:23: error: ISO C++ forbids declaration of `Q_OBJECT' with no type
mainwindow.h:23: error: expected `;' before "public"
mainwindow.h:27: error: `QCloseEvent' has not been declared
mainwindow.h:27: error: ISO C++ forbids declaration of `event' with no type
mainwindow.h:29: error: expected `:' before "slots"
mainwindow.h:30: error: expected primary-expression before "void"
mainwindow.h:30: error: ISO C++ forbids declaration of `slots' with no type
mainwindow.h:30: error: expected `;' before "void"
mainwindow.h:42: error: `QWidget' has not been declared
mainwindow.h:42: error: ISO C++ forbids declaration of `window' with no type
mainwindow.h:52: error: expected `,' or `...' before '&' token
mainwindow.h:52: error: ISO C++ forbids declaration of `QString' with no type
mainwindow.h:61: error: ISO C++ forbids declaration of `QToolBar' with no type
mainwindow.h:61: error: expected `;' before '*' token
mainwindow.h:62: error: ISO C++ forbids declaration of `QToolBar' with no type
mainwindow.h:62: error: expected `;' before '*' token
main.cpp: In function `int main(int, char**)':
main.cpp:6: error: `mdi' was not declared in this scope
main.cpp:6: error: `Q_INIT_RESOURCE' was not declared in this scope
main.cpp:8: error: `QApplication' was not declared in this scope
main.cpp:8: error: expected `;' before "app"
main.cpp:10: error: 'class mainWindow' has no member named 'show'
main.cpp:11: error: `app' was not declared in this scope
main.cpp:6: warning: unused variable 'mdi'
main.cpp:6: warning: unused variable 'Q_INIT_RESOURCE'
main.cpp:8: warning: unused variable 'QApplication'
main.cpp:11: warning: unused variable 'app'
mingw32-make[1]: *** [release/main.o] Error 1
mingw32-make[1]: Leaving directory `D:/Proyectos/myproject/Levedit'
mingw32-make: *** [release] Error 2

So I tried this:
D:\Proyectos\myproject\Levedit>qmake -project

D:\Proyectos\myproject\Levedit>qmake -makefile

This way qmake generates the pro file automatically. Then type:

D:\Proyectos\myproject\Levedit>mingw32-make

Exactly the same error outputs. But this time, in the console, I see new outputs, pay attention to:

"c:\iwmake\build_mingw_opensource\include\QtCore" -I"c:\iwmake\build_mingw_opensourc
e\include\QtGui"

This dir appears many times, It seems that the makefile generated by qmake is pointing to a directory that is not my qt directory. But I have set the environment variables correctly: QTDIR = D:\Proyectos\Libraries\CPP\Mingw\Qt\4.4.2. No problem when compiling in Code Blocks without custom makefile because my Code Blocks global variables are correctly configured, so this works for simple qt samples. But, when using a custom make file, the ide global variables aren't used. In theory, as I also have my system environment var, QTDIR, correctly, this must work too, but for some reason this doesn't enough. The qmake made makefile is pointing to "c:\iwmake\..." and not to my QTDIR directory.

Ok, at least now I know that the problem is not in my CB project configuration. It is in my QT configuration. Anyway, any ideas how to solve it?

Thanks for read, JH

Edited September 28:

My mistake, one of two problems solved. I configured QTDIR in environment variables but I didn't add qt bin directory to path variable. Now I can build with mingw32-make outside Code::Blocks. Now, let see if I can do it using Code::Blocks. Also, there is an undefined reference error, the linker says "release\main.o:main.cpp:(.text+0x56)||undefined reference to `qInitResources_mdi()'|". But, I think this is not due to Code::Blocks configuration but something wrong in my code.

Edited again:

Another mistake, I forgot to change the resource file name in my code to the actual resource file name in my project directory. Now I able to compile correctly from command line using mingw32-make, the exe appears in my release directory and until now it works as expected. But every time I try to compile in Code::Blocks the following output is returned:

mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `D:/Proyectos/Hellsing Fan Game/Levedit'
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtCore" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtCore" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtGui" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtGui" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include" -I"." -I"d:\Proyectos\Libraries\CPP\Mingw\Qt\4.4.2\include\ActiveQt" -I"release" -I"." -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\mkspecs\win32-g++" -o release\mainwindow.o mainwindow.cpp
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtCore" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtCore" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtGui" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include\QtGui" -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\include" -I"." -I"d:\Proyectos\Libraries\CPP\Mingw\Qt\4.4.2\include\ActiveQt" -I"release" -I"." -I"..\..\Libraries\CPP\Mingw\Qt\4.4.2\mkspecs\win32-g++" -o release\mdichild.o mdichild.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o release\Levedit.exe release/main.o release/mainwindow.o release/mdichild.o release/moc_mainwindow.o release/moc_mdichild.o release/qrc_levedit.o  -L"d:\Proyectos\Libraries\CPP\Mingw\Qt\4.4.2\lib" -lmingw32 -lqtmain -lQtGui4 -lQtCore4
release/moc_mainwindow.o:moc_mainwindow.cpp:(.text+0x0): multiple definition of `mainWindow::metaObject() const'
mingw32-make[1]: Leaving directory `D:/Proyectos/Hellsing Fan Game/Levedit'
release/mainwindow.o:mainwindow.cpp:(.text+0x3550): first defined here
release/moc_mainwindow.o:moc_mainwindow.cpp:(.text+0x10): multiple definition of `mainWindow::qt_metacast(char const*)'
release/mainwindow.o:mainwindow.cpp:(.text+0x3560): first defined here
release/moc_mainwindow.o:moc_mainwindow.cpp:(.text+0x60): multiple definition of `mainWindow::qt_metacall(QMetaObject::Call, int, void**)'
release/mainwindow.o:mainwindow.cpp:(.text+0x5780): first defined here
release/moc_mainwindow.o:moc_mainwindow.cpp:(.data+0x0): multiple definition of `mainWindow::staticMetaObject'
release/mainwindow.o:mainwindow.cpp:(.data+0x0): first defined here
release/moc_mdichild.o:moc_mdichild.cpp:(.text+0x0): multiple definition of `MdiChild::metaObject() const'
release/mdichild.o:mdichild.cpp:(.text+0xad0): first defined here
release/moc_mdichild.o:moc_mdichild.cpp:(.text+0x10): multiple definition of `MdiChild::qt_metacast(char const*)'
release/mdichild.o:mdichild.cpp:(.text+0xae0): first defined here
release/moc_mdichild.o:moc_mdichild.cpp:(.text+0x60): multiple definition of `MdiChild::qt_metacall(QMetaObject::Call, int, void**)'
release/mdichild.o:mdichild.cpp:(.text+0xb30): first defined here
release/moc_mdichild.o:moc_mdichild.cpp:(.data+0x0): multiple definition of `MdiChild::staticMetaObject'
release/mdichild.o:mdichild.cpp:(.data+0x0): first defined here
collect2: ld returned 1 exit status
mingw32-make[1]: *** [release\Levedit.exe] Error 1
mingw32-make: *** [Release] Error 2
Process terminated with status 2 (0 minutes, 19 seconds)
0 errors, 0 warnings

Again, what are the correctly CB settings to successfully compile using a qmake generated makefile?

Thanks for read, JH
« Last Edit: September 29, 2008, 04:10:17 am by JHAx86 »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Can't compile qt4 projects when using custom makefiles
« Reply #3 on: September 30, 2008, 04:25:55 am »
You know as much as anyone on this forum; you have to compare the commands Code::Blocks outputs to the make command that works on the command line.

Are they the same?

If not, does the one Code::Blocks output work on the command line?

If it does, does it still work when the window's PATH Environment variable is set to the Compiler Paths set in Code::Blocks?

If it fails then, add the needed paths to the additional path area for the Compiler.

Tim S



C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline vri

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Can't compile qt4 projects when using custom makefiles
« Reply #4 on: September 30, 2008, 08:57:24 am »

Offline JHAx86

  • Single posting newcomer
  • *
  • Posts: 7
Re: Can't compile qt4 projects when using custom makefiles
« Reply #5 on: September 30, 2008, 06:48:30 pm »
I can't believe this thing exists :D

The mdi example compiles in release and debug with it. And for now my project (it uses mdi too so I started from the example) is growing. For some reason I didn't get with it googling, maybe because English is not my natural language. Very thanks you.

Anyway, stahta01. No, no all my paths were correctly configured. After fix it, I was able to compile in release mode. But now I'm using the plugin, and I recommend it to everybody.

Good bye.
« Last Edit: October 18, 2008, 08:10:01 pm by JHAx86 »

Offline pacorrop

  • Single posting newcomer
  • *
  • Posts: 6
Re: Can't compile qt4 projects when using custom makefiles
« Reply #6 on: October 18, 2008, 11:13:36 am »
One point:

When mingw32-make says "no rule defined for cleanRelease and cleanDebug" you have to go to project's build options, and in the last tab "make commands" be sure to change this in all targets (i.e., Debug/Release):

Clean project/target: $make -f $makefile clean$target
Dist-clean project/target: $make -f $makefile distclean$target

for this:

Clean project/target: $make -f $makefile $target-clean
Dist-clean project/target: $make -f $makefile $target-distclean

So, you'll be able to compile from inside C::B (if this was your only problem :P)

Offline JHAx86

  • Single posting newcomer
  • *
  • Posts: 7
Re: Can't compile qt4 projects when using custom makefiles
« Reply #7 on: October 18, 2008, 08:17:46 pm »
Be changing the default:

Clean project/target: $make -f $makefile clean$target
Dist-clean project/target: $make -f $makefile distclean$target

for what you say:

Clean project/target: $make -f $makefile $target-clean
Dist-clean project/target: $make -f $makefile $target-distclean

It solves the error "no rule defined for cleanRelease and cleanDebug". But there were others errors. So I continue using the Qtworkbench plugin, and all goes right for now. My project is growing.

Thanks.

Grand777

  • Guest
Re: Can't compile qt4 projects when using custom makefiles
« Reply #8 on: April 22, 2009, 09:08:34 am »
Be changing the default:

Clean project/target: $make -f $makefile clean$target
Dist-clean project/target: $make -f $makefile distclean$target

for what you say:

Clean project/target: $make -f $makefile $target-clean
Dist-clean project/target: $make -f $makefile $target-distclean

It solves the error "no rule defined for cleanRelease and cleanDebug". But there were others errors. So I continue using the Qtworkbench plugin, and all goes right for now. My project is growing.

Thanks.

so you're project is growing can you post other topics please.,.,i will active to it if you post another topic in this discussion.,,.

_________________
Ceiling Fan



Offline JHAx86

  • Single posting newcomer
  • *
  • Posts: 7
Re: Can't compile qt4 projects when using custom makefiles
« Reply #9 on: April 22, 2009, 04:57:51 pm »
so you're project is growing can you post other topics please.,.,i will active to it if you post another topic in this discussion.,,.

do you have problems with qt? pacorrop post will be the solution for most cases. If that doesn't work then try the Qtworkbench plugin, it worked for me. If you don't want the plugin then remember that you need a qmake generated makefile, and if you fail compiling from CB then compile from command line. I can't explain why this specific project i'm working on does not compile in CB without use the plugin. Simpler projects have no problems anymore.