简体   繁体   English

Qt - 编译时出现错误 2

[英]Qt - Error 2 at compile time

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:运行项目测试的构建步骤...
16:50:24: Configuration unchanged, skipping qmake step. 16:50:24:配置不变,跳过 qmake 步骤。
16:50:24: Starting: "C:\\QtSDK\\QtCreator\\bin\\jom.exe" 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"." 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"..\\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 -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"." 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"..\\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 -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 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: C:\\Documents and Settings\\dfuser\\Desktop\\test-build-desktop-Qt_4_8_1_for_Desktop_- MSVC2008 _Qt_SDK__Debug\\Makefile.Debug [debug\\main.obj] 错误 2

jom 1.0.8 - empower your cores 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 jom: C:\\Documents and Settings\\dfuser\\Desktop\\test-build-desktop-Qt_4_8_1_for_Desktop_- MSVC2008 _Qt_SDK__Debug\\Makefile [debug] 错误 2
16:50:24: The process "C:\\QtSDK\\QtCreator\\bin\\jom.exe" exited with code 2. 16:50:24:进程“C:\\QtSDK\\QtCreator\\bin\\jom.exe”退出,代码2。
Error while building project test (target: Desktop)构建项目测试时出错(目标:桌面)
When executing build step 'Make'执行构建步骤“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 cl nor found;我不知道它是否相关,但在收到此错误之前,我收到了有关cl的常见错误,也未找到; I solved adding the path to cl in the project settings.我解决了在项目设置中添加cl的路径。

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.我已经解决了:如果出现 dll 错误,请尝试直接执行 cl.exe (C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\cl),这是因为您的环境设置不正确。 So, you need to call vcvarsall.bat before lunch QtCreator.所以,你需要在午餐前调用 vcvarsall.bat QtCreator。 To do that each time, you can create a .bat file which contains the following:要每次都这样做,您可以创建一个 .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”

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

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 中遇到了同样的问题,我是这样解决的。

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.当您启动它时,您将加载 int cmd,然后找到您的项目。 Then you can type: qmake and after that make and then you have built project然后你可以输入: qmake,然后在make之后你已经构建了项目

If it doesn't work try to go trough the DOCUMENTATION to 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 make command.因为它们可能没有设置为显示给make命令。 If you don't want to bother with minigw you can maybe check your environmental variables if they have set path: to make如果您不想打扰 minigw,您可以检查您的环境变量,如果它们设置了 path: to make

I create a new project with the same name in other folder, copy internal files except <project_name>.pro.user file.我在其他文件夹中创建了一个同名的新项目,复制除了 <project_name>.pro.user 文件之外的内部文件。

This work form me, I don't know why, but removing <project_name>.pro.user file from my original project error continues.这项工作形成了我,我不知道为什么,但是从我的原始项目错误中删除 <project_name>.pro.user 文件继续。

我多次遇到这个问题,对我来说修复它的只是重命名项目所在的文件夹。或者,您可以创建一个新项目,然后将所有头文件和源文件复制到该新项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM