How to debug qmake?

Some day, you may want to debug qmake, … for fun. How to debug qmake? In the source directory of qmake(c:\Qt5.12.1\5.12.1\Src\qtbase\qmake), you will find a .pro file, which would trigger your attempt of opening it in Qt creator and debugging it as an ordinary qt project. Unfortunately, you’ll soon find you can not even build out qmake.exe, nevertheless debug it. You can find the following statements at the beginning of

# This project is not actually used to build qmake, but to support development
# with Qt Creator. The real build system is made up by the Makefile templates
# and the configures.

Yes, is not an ordinary project file. You can not get much from it except explore the project’s source code in Qt creator. As the statement says, you can build qmake.exe using the configure script. The built qmake.exe would be in c:\qtbuild\qtbase\bin\.

You can debug the generated qmake.exe in Qt creator. Click the menu Debug/Start Debugging/Start and Debug External Application, you’ll be presented with a dialog, where you can specify the program to debug(c:\qtbuild\qtbase\bin\qmake.exe), its command line arguments(c:\Qt5.12.1\5.12.1\Src –), the working directory(C:\qtbuild). You can tick “Break on main” to break on the main function after starting the program. Now, click the “OK” button, Qt creator will run the program.

The result may disappoint you. Qmake was started and run successfully but terminated in a blink. Why didn’t it stop at the main function?  Does the generated qmake.exe not include debug information in it? How to check if a .exe program has debug symbols in it? I know a debug version of .exe has a debug section in its image. But I cannot remember the tools to verify if the debug sections or debug headers exist in the .exe file. I read the post, this post, and this post, and got to know maybe I can use the tools like dumpbin, objdump, nm, etc to check the content of the .exe file to see if the debug symbols are indeed there. But I have not these tools at hand. I does have a tool accompanied by Qt: gdb. I ran this tool against the generated qmake.exe: gdb c:\qtbuild\qtbase\bin\qmake.exe. A line of the output confirms there is no debug information in it:

Reading symbols from qtbase/bin/qmake.exe…(no debugging symbols found)…done.

Things get a little weird now because by checking the Makefile that is used to make qmake.exe, the -g option is enabled:


So theoretically, qmake.exe should be in debug mode. Why gdb cannot find debug symbols in the debug version of qmake.exe? This post gave me a hint. In fact, the debug symbols in the .obj files are stripped during the linking due to the -s option.

EXTRA_LFLAGS = -static -s -lole32 -luuid -ladvapi32 -lkernel32 -lnetapi32

The solution is straightforward: Remove the -s option from EXTRA_LFLAGS and rebuild qmake. Now qmake.exe becomes much fatter as it includes the debug symbols.

Now you can debug it in the Qt creator, setting breakpoints, stepping into, stepping over, etc.


If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply