首页 > 解决方案 > Qt 在命令行中使用“mingw32-make”并出现 .exe 文件生成错误

问题描述

qmake -project到目前为止,我已经qmake在命令行中使用了 .pro 文件的配置,Makefile.Debug 和 Makefile.Release 已经解决。但是当我尝试mingw32-make在命令行中使用为我的项目生成 .exe 时会发生错误。

错误意味着在线:

64 ****missing separator ...Stop

但在这种情况下,我已经为mingw32-make.exe和设置了所有环境变量qmake.exe

有人说我应该在makefile.release中添加一个Tab而不是一个空格,在错误发生的地方(错误位置只有一个“<<”),但是当我进行更改时会发生其他错误。而且我认为由于Makefiles都是由qmake命令自动生成的,所以也许这不是真正的问题......这是错误信息和Makefile.Release文件的一部分供参考:

Setting up environment for Qt usage...
Remember to call vcvarsall.bat to complete environment setup!

D:\qt5.10\5.9.2\msvc2017_64>cd D:\qtProgramme\helloworld

D:\qtProgramme\helloworld>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'D:/qtProgramme/helloworld'
Makefile.Release:64: *** missing separator.  Stop.
mingw32-make[1]: Leaving directory 'D:/qtProgramme/helloworld'
Makefile:36: recipe for target 'release' failed
mingw32-make: *** [release] Error 2

D:\qtProgramme\helloworld>

这是 Makefile.Release:

#############################################################################
# Makefile for building: helloworld
# Generated by qmake (3.1) (Qt 5.9.2)
# Project:  helloworld.pro
# Template: app
#############################################################################

MAKEFILE      = Makefile.Release

####### Compiler, tools and options

CC            = cl
CXX           = cl
DEFINES       = -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG
CFLAGS        = -nologo -Zc:wchar_t -FS -Zc:strictStrings -O2 -MD -W3 -w44456 -w44457 -w44458 $(DEFINES)
CXXFLAGS      = -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc $(DEFINES)
INCPATH       = -I. -I. -I..\..\qt5.10\5.9.2\msvc2017_64\include -I..\..\qt5.10\5.9.2\msvc2017_64\include\QtWidgets -I..\..\qt5.10\5.9.2\msvc2017_64\include\QtGui -I..\..\qt5.10\5.9.2\msvc2017_64\include\QtANGLE -I..\..\qt5.10\5.9.2\msvc2017_64\include\QtCore -Irelease -I..\..\qt5.10\5.9.2\msvc2017_64\mkspecs\win32-msvc 
LINKER        = link
LFLAGS        = /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"
LIBS          = /LIBPATH:D:\qt5.10\5.9.2\msvc2017_64\lib D:\qt5.10\5.9.2\msvc2017_64\lib\qtmain.lib /LIBPATH:C:\utils\my_sql\my_sql\lib /LIBPATH:C:\utils\postgresql\pgsql\lib shell32.lib D:\qt5.10\5.9.2\msvc2017_64\lib\Qt5Widgets.lib D:\qt5.10\5.9.2\msvc2017_64\lib\Qt5Gui.lib D:\qt5.10\5.9.2\msvc2017_64\lib\Qt5Core.lib 
QMAKE         = D:\qt5.10\5.9.2\msvc2017_64\bin\qmake.exe
IDC           = idc
IDL           = midl /NOLOGO
ZIP           = zip -r -9
DEF_FILE      = 
RES_FILE      = 
COPY          = copy /y
SED           = $(QMAKE) -install sed
COPY_FILE     = copy /y
COPY_DIR      = xcopy /s /q /y /i
DEL_FILE      = del
DEL_DIR       = rmdir
MOVE          = move
CHK_DIR_EXISTS= if not exist
MKDIR         = mkdir
INSTALL_FILE    = copy /y
INSTALL_PROGRAM = copy /y
INSTALL_DIR     = xcopy /s /q /y /i
QINSTALL        = D:\qt5.10\5.9.2\msvc2017_64\bin\qmake.exe -install qinstall
QINSTALL_PROGRAM = D:\qt5.10\5.9.2\msvc2017_64\bin\qmake.exe -install qinstall -exe

####### Output directory

OBJECTS_DIR   = release

####### Files

SOURCES       = main.cpp 
OBJECTS       = release\main.obj

DIST          =   main.cpp
QMAKE_TARGET  = helloworld
DESTDIR        = release\ #avoid trailing-slash linebreak
TARGET         = helloworld.exe
DESTDIR_TARGET = release\helloworld.exe

####### Implicit rules

.SUFFIXES: .c .cpp .cc .cxx

{.}.cpp{release\}.obj::
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
    $<
<<

{.}.cc{release\}.obj::
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
    $<
<<

{.}.cxx{release\}.obj::
    $(CXX) -c $(CXXFLAGS) $(INCPATH) -Forelease\ @<<
    $<
<<

{.}.c{release\}.obj::
    $(CC) -c $(CFLAGS) $(INCPATH) -Forelease\ @<<
    $<
<<

####### Build rules

first: all
all: Makefile.Release  $(DESTDIR_TARGET)

$(DESTDIR_TARGET):  $(OBJECTS) 
    $(LINKER) $(LFLAGS) /MANIFEST:embed /OUT:$(DESTDIR_TARGET) @<<
release\main.obj
$(LIBS)
<<

qmake: FORCE
    @$(QMAKE) -o Makefile.Release helloworld.pro

qmake_all: FORCE

标签: qtmakefileqmake

解决方案


您正在使用 Qt 的 MSVC 版本。这可以通过安装路径(D:\qt5.10\5.9.2\msvc2017_64)和输出“记得调用vcvarsall.bat完成环境设置!”来推断。

来自 Qt 的 MSVC 构建的 QMake 生成与 MSVC 兼容的 makefile(至少默认情况下)。

安装 Qt 的 MinGW 构建,您可以将 MinGW 工具链用于您的项目。


推荐阅读