Donotalo
Donotalo

Reputation: 13025

Qt 4.8.2 With GCC 4.7.0.1 Keeps Crashing

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:

So, what's causing the runtime crash?

EDIT

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

Upvotes: 2

Views: 4019

Answers (2)

rdrmntn
rdrmntn

Reputation: 466

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)

Upvotes: 0

Michael Burr
Michael Burr

Reputation: 340168

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.

Upvotes: 4

Related Questions