2

I've downloaded Qt 4.8.2 library, Qt Creator 2.5.2, and manually installed MingW with w32api version 3.13 and GCC/g++ version 4.7.0.1. My OS is Windows 7 Ultimate x64.

I can create a sample "Plain C++ project" in Qt Creator; compile and run that console application using g++ without any issue.

But I cannot run a Qt application. I used Qt Creator, created a dummy Qt Application using Creator's "Qt Gui Application" template. The project can be compiled successfully, without any error or warning. But the binary keeps crashing when I try to run (both from Qt Creator and Windows Explorer) it. Both debug and release builds crash. It crashes even before showing main window.

MingW is installed in C:\MingW and C:\MingW\bin is in PATH. Qt is installed in C:\Qt\4.8.2 and C:\Qt\4.8.2\bin is in PATH.

I analyzed generated exe of the Qt Gui Application output with Dependency Walker and found that it found all required DLLs:

  • c:\windows\system32\KERNEL32.DLL
  • c:\windows\system32\MSVCRT.DLL
  • c:\mingw\bin\LIBGCC_S_DW2-1.DLL
  • c:\mingw\bin\LIBSTDC++-6.DLL
  • c:\qt\4.8.2\bin\QTCORE4.DLL
  • c:\qt\4.8.2\bin\QTGUI4.DLL

So, what's causing the runtime crash?

EDIT

I also tried Qt's example projects: 2dpainting and addressbook - both crashed when they were launched.

Donotalo
  • 12,748
  • 25
  • 83
  • 121
  • 3
    Usually people in such situation debug and analyze the crash with debugger. – Öö Tiib Sep 12 '12 at 04:31
  • @ÖöTiib: Well it is almost obvious that the Qt library is the reason of crash. I was thinking that my be I'm missing something silly - may be some configuration - I'm not too accustomed to GCC/g++. – Donotalo Sep 12 '12 at 05:24
  • @ÖöTiib: Besides, I can't "build Qt debug libraries" with the shortcut created by Qt in Windows start menu. After running the file for ~15 minutes, at one point it exits saying that it cannot allocate memory - something like 10^9 or 10^10 bytes - not sure the exact size. Building the debug library is only required to debug Qt library - which I want to avoid at the moment. – Donotalo Sep 12 '12 at 05:26
  • It might be version mismatch. For example that Qt library is compiled with G++ 4.4.0 but your code is compiled with 4.7.0. Such things usually give linker errors, not crashes, however. – Öö Tiib Sep 12 '12 at 05:50
  • Run your program in a debugger, check the stack trace to see where in _your_ program it crashes, and examine variables there. It's more likely that you did something wrong that there is an error in Qt. – Some programmer dude Sep 12 '12 at 05:50
  • @JoachimPileborg: is it even possible? :) because all I did was created a Qt GUI Application using Qt's template. The project itself is auto generated by Qt. I did nothing on top of it. just compiled it and run. However, I'm out of home now. I'll try to debug when I get back to home. – Donotalo Sep 12 '12 at 05:59
  • In that case it might be some kind of version mismatch like suggested by @ÖöTiib. – Some programmer dude Sep 12 '12 at 06:38
  • @JoachimPileborg: too bad. i wanted to use newer version of g++ with Qt. :( – Donotalo Sep 12 '12 at 06:39
  • @Donotalo migrating whatever C++ library into officially not supported context (OS/compiler) is hard work. C++ did evolve by large step 2011 and there are lot of cases where backward compatibility is not achieved by the new standard. – Öö Tiib Sep 12 '12 at 06:57
  • @ÖöTiib Qt doesn't need to be migrated to use a newer GCC. All the OP has to do is rebuild the Qt libraries with his preferred compiler. As Michael suggests in his answer. – rubenvb Feb 11 '13 at 13:53

2 Answers2

4

You should build Qt with the MinGW compiler you're using to build your application. GCC is generally less sensitive to binary compatibility issues than MSVC is, but Qt is a big, complex framework library. If anything would expose those kinds of issues, Qt would probably be on the short list.

Building Qt is pretty straightforward, but it takes a lot of time and there always seems to be two or three patches I need to make to get things to build successfully.

The last time I built Qt (4.7.3) with MinGW, I had to make the following patches - I'm not sure whether they will still apply to Qt 4.8:

  • make sure not to enable C++11 mode in the compiler - there are several macros with concatenated string literals that break under the new C++11 extended literal syntax
  • there is a problem with how some distributions of MinGW incorporate the Microsoft extensions to float.h - I had to sometimes had to add the line:

    #include_next <float.h>
    

    to the end of the MinGW-specific float.h so the generic GCC float.h would get processed properly. I had to do this for nuwen 4.7.0 lib/gcc/i686-pc-mingw32/4.7.0/include/float.h and TDM 4.6.1 32-bit distro lib/gcc/mingw32/4.6.1/include/float.h (the 64-bit distro of TDM didn't need this patch).

  • patch qmake\Makefile.win32-g++ and qmake\Makefile.win32-g++-sh to remove the -static-libstdc++ option that GCC doesn't recognize (and now errors out on instead of ignores)

  • patch mkspecs/win32-g++/qmake.conf to move the -Wl, in the QMAKE_LFLAGS_EXCEPTIONS_ON macro to its proper place in QMAKE_FLAGS:

    QMAKE_LFLAGS        = -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
    QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads
    
  • copy make.exe to mingw32-make.exe in MinGW's bin directory if there's not already a mingw32-make.exe

Then building Qt consists of:

  set QTDIR=<location of Qt source directory>  # where configure.exe is
  set PATH=%QTDIR%\bin;c:\MinGW\bin;%PATH%
  set INCLUDE=
  set LIB=
  cd %QTDIR%

  mingw32-make confclean    # (this should fail the first time, since there's nothing to clean)
  configure.exe -opensource -debug-and-release -nomake examples -nomake demos -nomake tests -platform win32-g++  # and accept the GPL license
  mingw32-make

This takes a while... hopefully nothing else will need patching.

Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • this makes sense. will try later sometime. – Donotalo Sep 13 '12 at 04:37
  • @cubuspl42: that's in line with my experience. Maybe people who do it a lot know of tricks to speed it up or parallelize it? I build both debug and release; doing only release might save some time if you don't need to debug into the Qt libs. – Michael Burr Sep 15 '12 at 18:29
  • @Michael Burr Not building WebKit module speeds that up quite a lot. I've read all that info on the internet, I've never built QT personally. – cubuspl42 Sep 15 '12 at 18:36
  • Why do you suggest not using C++11 mode? I haven't had anything break in my experience. Do you mean compile errors in the Qt libraries or in your own code? – rubenvb Feb 11 '13 at 13:54
  • @rubenvb: building the Qt 4.7.3 library sources had problems with C++11 (or at least GCC MinGW 4.7.2 in C++11 mode). I haven't tried C++11 with a newer version of Qt, so those problems have probably been fixed. – Michael Burr Feb 11 '13 at 15:27
  • I just tried building 1t 4.8.4 with MinGW in C++11 mode (`-std=gnu++11`) and it fails when building a 3rd party JavaScriptCore library. I imagine if WebKit were disabled from the build C++11 might work OK. – Michael Burr Jun 23 '13 at 22:37
0

I also got this problem. I'm a Qt n00b and tought, when installing Qt-libraries, that "well I already have Mingw installed so I skip installing the Mingw that comes with Qt". That gave me prolems. When installing mingw that came with Qt everything worked ok.

So my advice to anyone googling to this question (like I did) is to instead of using your already installed Mingw, install the one with Qt and use that (otherwise you have to build the Qt libraries within your Mingw, like the answer from Michael Burr)

rdrmntn
  • 406
  • 2
  • 6
  • 19