Qt 4.8.2使用GCC 4.7.0.1保持崩溃 [英] Qt 4.8.2 With GCC 4.7.0.1 Keeps Crashing

查看:136
本文介绍了Qt 4.8.2使用GCC 4.7.0.1保持崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载Qt 4.8.2库,Qt Creator 2.5.2,并手动安装MingW与w32api版本3.13和GCC / g ++版本4.7.0.1。我的操作系统是Windows 7 Ultimate x64。



我可以在Qt Creator中创建一个示例Plain C ++ project编译和运行控制台应用程序使用g ++没有任何问题。



但我不能运行一个Qt应用程序。我使用Qt Creator,使用创建者的Qt Gui应用程序模板创建一个虚拟的Qt应用程序。项目可以成功编译,没有任何错误或警告。但是当我尝试运行( Qt Creator Windows资源管理器)时,二进制文件会崩溃。调试和发行版本都崩溃。



MingW安装在 C:\MingW C:\MingW\bin 位于 PATH 中。 Qt安装在 C:\Qt\4.8.2 C:\Qt\4.8.2\bin PATH



我用Dependency Walker分析了Qt Gui应用程序输出的生成的exe,发现找到了所有必需的DLL:




  • 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





我也试过Qt的示例项目:2dpainting和addressbook - 都在启动时崩溃。

解决方案

您应该使用MinGW编译器构建Qt使用构建您的应用程序。 GCC通常不如MSVC对二进制兼容性问题敏感,但Qt是一个大的,复杂的框架库。如果任何事情会暴露这些问题,Qt可能在短列表。



构建Qt是相当简单,但它需要很多时间,



最后一次我用MinGW构建Qt(4.7.3),我不得不使用以下补丁 - 我不确定他们是否仍然适用于Qt 4.8:




  • 确保不启用C ++ 11模式在编译器中 - 有几个具有连接的字符串文字的宏,它们在新的C ++ 11扩展文字语法下破坏了

  • 有一个MinGW的一些分布Microsoft扩展 float.h - 我有时必须添加行:

      #include_next< float.h> 

    到特定于MinGW的 float.h 所以通用的GCC float.h 将得到正确处理。我不得不这样做为nuwen 4.7.0 lib / gcc / i686-pc-mingw32 / 4.7.0 / include / float.h 和TDM 4.6.1 32位distro lib / gcc / mingw32 / 4.6.1 / include / float.h (TDM的64位发行版不需要这个补丁)。

    / li>
  • 补丁 qmake\Makefile.win32-g ++ qmake\Makefile.win32-g ++ -sh 删除GCC无法识别的 -static-libstdc ++ 选项(现在错误而不是忽略)


  • patch mkspecs / win32-g ++ / qmake.conf 移动 -Wl, / code>:中的正确位置,将 QMAKE_LFLAGS_EXCEPTIONS_ON 中的 b

      QMAKE_LFLAGS = -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc 
    QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads


  • 复制 code>到目录中的 mingw32-make.exe ,如果还没有 mingw32-make.exe




>

  set QTDIR =< Qt源目录的位置> #where configure.exe is 
set PATH =%QTDIR%\bin; c:\MinGW\bin;%PATH%
set INCLUDE =
set LIB =
cd%QTDIR%

mingw32-make confclean#(这应该是第一次失败,因为没有什么要清理)
configure.exe -opensource -debug-and-release -nomake examples - nomake demos -nomake tests -platform win32-g ++#并接受GPL许可证
mingw32-make

这需要一段时间...希望没有其他的东西需要修补。


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.

解决方案

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.

这篇关于Qt 4.8.2使用GCC 4.7.0.1保持崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆