C++ Qt - 编译时出现错误 2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10434064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:03:03  来源:igfitidea点击:

Qt - Error 2 at compile time

c++qtcompiler-errorsmakefile

提问by user1372813

I just downloaded Qt SDK 4.8.1 and, after installing it, I simply tried to compile a default C++ project, but I got this strange error.

我刚刚下载了 Qt SDK 4.8.1,安装后,我只是尝试编译一个默认的 C++ 项目,但出现了这个奇怪的错误。

16:50:24: Running build steps for project test...
16:50:24: Configuration unchanged, skipping qmake step.
16:50:24: Starting: "C:\QtSDK\QtCreator\bin\jom.exe"
cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\QtCore" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\QtGui" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\ActiveQt" -I"debug" -I"." -I"..\test" -I"." -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\mkspecs\win32-msvc2008" -Fodebug\ @C:\DOCUME~1\dfuser\IMPOST~1\Temp\main.obj.1464.0.jom
cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\QtCore" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\QtGui" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\ActiveQt" -I"debug" -I"." -I"..\test" -I"." -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\mkspecs\win32-msvc2008" -Fodebug\ @C:\DOCUME~1\dfuser\IMPOST~1\Temp\mainwindow.obj.1464.0.jom
C:\QtSDK\QtCreator\bin\jom.exe -f Makefile.Debug
jom: C:\Documents and Settings\dfuser\Desktop\test-build-desktop-Qt_4_8_1_for_Desktop_-MSVC2008_Qt_SDK__Debug\Makefile.Debug [debug\main.obj] Error 2

jom 1.0.8 - empower your cores

jom: C:\Documents and Settings\dfuser\Desktop\test-build-desktop-Qt_4_8_1_for_Desktop_-MSVC2008_Qt_SDK__Debug\Makefile [debug] Error 2
16:50:24: The process "C:\QtSDK\QtCreator\bin\jom.exe" exited with code 2.
Error while building project test (target: Desktop)
When executing build step 'Make'

16:50:24:运行项目测试的构建步骤...
16:50:24:配置不变,跳过 qmake 步骤。
16:50:24:开始:“C:\QtSDK\QtCreator\bin\jom.exe”
CL -c -nologo -Zm200 -Zc:wchar_t- -ZI -MDd -GR -EHsc-W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\QtCore" -I"........\QtSDK\Desktop\Qt\4.8.1\ msvc2008\include\QtGui" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include" -I"........\QtSDK\Desktop\Qt\ 4.8.1\msvc2008\include\ActiveQt" -I"debug" -I"。" -I"..\test" -I"." -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\mkspecs\win32-msvc2008" -Fodebug\ @C:\DOCUME~1\dfuser\IMPOST~1\Temp\main .obj.1464.0.jom
CL -c -nologo -Zm200 -Zc:wchar_t- -ZI -MDd -GR -EHsc-W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include\QtCore" -I"........\QtSDK\Desktop\Qt\4.8.1\ msvc2008\include\QtGui" -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\include" -I"........\QtSDK\Desktop\Qt\ 4.8.1\msvc2008\include\ActiveQt" -I"debug" -I"。" -I"..\test" -I"." -I"........\QtSDK\Desktop\Qt\4.8.1\msvc2008\mkspecs\win32-msvc2008" -Fodebug\ @C:\DOCUME~1\dfuser\IMPOST~1\Temp\mainwindow .obj.1464.0.jom
C:\QtSDK\QtCreator\bin\jom.exe -f Makefile.Debug
jom: C:MSVC2008_Qt_SDK__Debug\Makefile.Debug [debug\main.obj] 错误 2

jom 1.0.8 - 增强你的核心

jom: C:\Documents and Settings\dfuser\Desktop\test-build-desktop-Qt_4_8_1_for_Desktop_- MSVC2008_Qt_SDK__Debug\Makefile [debug] Error 2
16:50:24: 进程“C:\QtSDK\QtCreator\bin\jom. exe”以代码 2 退出。
构建项目测试时出错(目标:桌面)
执行构建步骤“Make”时

Does anyone know what is the cause?

有谁知道是什么原因?

I don't know if it's relevant or not, but before getting this error I got the common error about clnor found; I solved adding the path to clin the project settings.

我不知道它是否相关,但在收到此错误之前,我收到了有关或未找到的常见错误cl;我解决了cl在项目设置中添加路径的问题。

回答by hl037_

I've solved it : try to execute cl.exe directly (C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl) if you get a dll error, it's because your environment is not set correctly. So, you need to call vcvarsall.bat before lunch QtCreator. To do that each time, you can create a .bat file which contains the following:

我已经解决了:如果出现 dll 错误,请尝试直接执行 cl.exe (C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl),这是因为您的环境设置不正确。所以,你需要在午餐前调用 vcvarsall.bat QtCreator。要每次都这样做,您可以创建一个 .bat 文件,其中包含以下内容:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat

{Path to QtCreator}\qtcreator

{QtCreator 的路径}\qtcreator

(Correct the paths if your configuration is not the same)

(如果您的配置不相同,请更正路径)

You will need to execute this script to get QtCreator with the right environment variables, otherwise, the dll error appears but is not reported, and you get this "Error : 2"

您将需要执行此脚本以获取具有正确环境变量的 QtCreator,否则会出现 dll 错误但未报告,并且您会收到此“错误:2”

回答by Kahn

I had somewhat similar problem in Qt 5.3

我在 Qt 5.3 中遇到了类似的问题

21:22:03: Running steps for project Server...
21:22:03: Configuration unchanged, skipping qmake step.
21:22:03: Starting: "C:\Qt\Qt5.3.2\Tools\mingw482_32\bin\mingw32-make.exe" 
C:\make\bin; -f Makefile.Debug
Makefile:34: recipe for target 'debug' failed
process_begin: CreateProcess(NULL, C:\make\bin; -f Makefile.Debug, ...) failed.
make (e=2): The system cannot find the file specified.

mingw32-make: *** [debug] Error 2
21:22:05: The process "C:\Qt\Qt5.3.2\Tools\mingw482_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project Server (kit: Desktop Qt 5.3 MinGW 32bit)
When executing step "Make"

I did the following to get rid of the error.
From the left pane of the Qt,

我做了以下操作来消除错误。
从 Qt 的左窗格中,

Projects > Build > Build Environment:

Check the Clear System environment

回答by Amir Hossein

In Linux terminal:

在 Linux 终端中:

sudo apt-get install build-essential cmake libqt4-dev

I'm sorry I don't know why this code works but I had the same problem in Linux and I solved it this way.

对不起,我不知道为什么这段代码有效,但我在 Linux 中遇到了同样的问题,我是这样解决的。

回答by user123_456

Okay so you can do this.

好的,所以你可以这样做。

Go to Start->Choose Qt folder->minigw

转到开始->选择Qt文件夹->minigw

When you start it you will be loaded int cmd, after that locate your project. Then you can type: qmakeand after that makeand then you have built project

当您启动它时,您将加载 int cmd,然后找到您的项目。然后你可以输入:qmake,然后在make之后你已经构建了项目

If it doesn't work try to go trough the DOCUMENTATIONto see how to use minigw when you are using Qt.

如果它不起作用,请尝试通过文档查看在使用 Qt 时如何使用 minigw。

If you need anymore help let me know I'll be glad to help you.

如果您需要更多帮助,请告诉我,我很乐意为您提供帮助。

EDIT:

编辑:

One more thing. In your question problem may be connected to environmental variables. As they are not probably set to show to the makecommand. If you don't want to bother with minigw you can maybe check your environmental variables if they have set path: to make

还有一件事。在您的问题中,问题可能与环境变量有关。因为它们可能没有设置为显示给make命令。如果您不想打扰 minigw,您可以检查您的环境变量,如果它们设置了 path: to make