静态构建Qt后,我无法在Windows 7上编译/链接应用程序(GNU分配器错误)

After building Qt statically, I can't get to compile / link an application on Windows 7 (GNU allocator error)

本文关键字:应用程序 链接 编译 GNU 错误 分配器 Qt 构建 Windows 静态      更新时间:2023-10-16

我正在尝试将我的应用程序与Qt静态链接。这是我所做的:

  1. 下载了Qt库4.8.1
  2. 闽民
  3. 为Qt配置了:

    配置 -release -platform win32-g++ -nomake examples -nomake demos -no-rtti-no-qt3support -no-scripttools -no-openssl -no-opengl -no-webkit -no-phonon-no-style-motif -no-style-cde -no-style-cleanlook -no-style-plastique -no-sql-sqlite

  4. 运行 Win32-make

  5. 在Qt Creator中设置我的项目(也来自SDK 4.8)以发布并使用静态库。

将配置 += 静态添加到 .pro 文件

我收到这个错误(显然有些不喜欢我的代码使用 std::vector<> ?

C:/MinGW/bin/mingw32-make.exe -f Makefile.Release
mingw32-make.exe[1]: Entering directory `C:/PhotoChop-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Release'
g++ -c -Os -momit-leaf-frame-pointer -fno-exceptions -Wall -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -DQT_NO_DYNAMIC_CAST -I"......Qt4.8.1includeQtCore" -I"......Qt4.8.1includeQtGui" -I"......Qt4.8.1include" -I"......Qt4.8.1includeActiveQt" -I"release" -I"." -I"..PhotoChop" -I"." -I"......Qt4.8.1mkspecswin32-g++" -o releasemainwindow.o ..PhotoChopmainwindow.cpp
In file included from c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/mingw32/bits/c++allocator.h:34:0,
                 from c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/bits/allocator.h:48,
                 from c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/string:43,
                 from ......Qt4.8.1include/QtCore/../../src/corelib/tools/qstring.h:54,
                 from ......Qt4.8.1include/QtCore/qstring.h:1,
                 from ......Qt4.8.1include/QtCore/../../src/corelib/kernel/qobject.h:48,
                 from ......Qt4.8.1include/QtCore/qobject.h:1,
                 from ......Qt4.8.1include/QtGui/../../src/gui/kernel/qwidget.h:46,
                 from ......Qt4.8.1include/QtGui/qwidget.h:1,
                 from ......Qt4.8.1includeQtGui/../../src/gui/widgets/qmainwindow.h:45,
                 from ......Qt4.8.1includeQtGui/qmainwindow.h:1,
                 from ......Qt4.8.1includeQtGui/QMainWindow:1,
                 from ..PhotoChop/mainwindow.h:4,
                 from ..PhotoChopmainwindow.cpp:1:
c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/ext/new_allocator.h: In instantiation of '__gnu_cxx::new_allocator<const PCOperator::OperatorInfo* const>':
c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/bits/allocator.h:92:11:   instantiated from 'std::allocator<const PCOperator::OperatorInfo* const>'
c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/bits/stl_vector.h:73:60:   instantiated from 'std::_Vector_base<const PCOperator::OperatorInfo* const, std::allocator<const PCOperator::OperatorInfo* const> >'
c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/bits/stl_vector.h:180:11:   instantiated from 'std::vector<const PCOperator::OperatorInfo* const>'
..PhotoChopmainwindow.cpp:55:35:   instantiated from here
c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/ext/new_allocator.h:82:7: error: 'const _Tp* __gnu_cxx::new_allocator<_Tp>::address(__gnu_cxx::new_allocator<_Tp>::const_reference) const [with _Tp = const PCOperator::OperatorInfo* const, __gnu_cxx::new_allocator<_Tp>::const_pointer = const PCOperator::OperatorInfo* const*, __gnu_cxx::new_allocator<_Tp>::const_reference = const PCOperator::OperatorInfo* const&]' cannot be overloaded
c:mingwbin../lib/gcc/mingw32/4.6.1/include/c++/ext/new_allocator.h:79:7: error: with '_Tp* __gnu_cxx::new_allocator<_Tp>::address(__gnu_cxx::new_allocator<_Tp>::reference) const [with _Tp = const PCOperator::OperatorInfo* const, __gnu_cxx::new_allocator<_Tp>::pointer = const PCOperator::OperatorInfo* const*, __gnu_cxx::new_allocator<_Tp>::reference = const PCOperator::OperatorInfo* const&]'
mingw32-make.exe[1]: Leaving directory `C:/PhotoChop-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Release'
mingw32-make.exe[1]: *** [release/mainwindow.o] Error 1
mingw32-make.exe: *** [release] Error 2
01:24:28: The process "C:MinGWbinmingw32-make.exe" exited with code 2.
Error while building project PhotoChop (target: Desktop)
When executing build step 'Make'

有什么想法吗?

基本上,

就目前而言,mingw 编译器与 msvc 编译器之间存在一些问题

std::vector<const PCOperator::OperatorInfo* const>

我用-platform win32-msvc2010和nmake而不是mingw32-make重新配置了qt,现在编译得很好。

我在配置参数中没有看到"-static"选项?