C++ QT 示例可执行文件将无法运行,缺少 QT5Cored.dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28732602/
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
QT example executables won't run, missing QT5Cored.dll
提问by Ashton
QT5Cored.dll is on my system @: C:\Qt\5.4\mingw491_32\bin folder
QT5Cored.dll 在我的系统上@: C:\Qt\5.4\mingw491_32\bin 文件夹
The Analogclock example and other projects will run in the IDE, but can Not be run from the created .exe files. When the EXE is launched the QT5Cored.dll missing error occurs.
QT installed it & doesn't know where it is?
Removed & reinstalled QT with same results.
Analogclock 示例和其他项目将在 IDE 中运行,但不能从创建的 .exe 文件中运行。启动 EXE 时,会发生 QT5Cored.dll 丢失错误。QT 安装了它并且不知道它在哪里?删除并重新安装 QT,结果相同。
Downloaded earler today. Version: 3.3.1, QT 5.4.1(MSCV 2010, 32 Bit), Built on Feb 20, 2015.
今天早点下载。版本: 3.3.1, QT 5.4.1(MSCV 2010, 32 Bit), 构建于 2015 年 2 月 20 日。
Any suggestions appreciated.
任何建议表示赞赏。
New error after DLL filles added to exe directory.
DLL 填充后添加到 exe 目录的新错误。
回答by fxam
To run it outside of Qt Creator, you have two choices:
要在 Qt Creator 之外运行它,您有两种选择:
- Copy the missing DLLs to the directory where the executable resides. For example if
analogclock.exe
is inc:\examples
, then copyC:\Qt\5.4\mingw491_32\bin\Qt5Cored.dll
and other required DLLs toc:\examples
. You may need to copy plugins files too. - Add
C:\Qt\5.4\mingw491_32\bin
to thePATH
environment variable.
- 将丢失的 DLL 复制到可执行文件所在的目录。例如,如果
analogclock.exe
在 中c:\examples
,则将C:\Qt\5.4\mingw491_32\bin\Qt5Cored.dll
其他所需的 DLL复制到c:\examples
. 您可能还需要复制插件文件。 - 添加
C:\Qt\5.4\mingw491_32\bin
到PATH
环境变量。
There are some ways to copy the missing DLLs:
有一些方法可以复制丢失的 DLL:
1. Use Windows Deployment Tool (windeployqt.exe) to copy required files
1.使用Windows部署工具(windeployqt.exe)复制需要的文件
- Open Command Prompt in one of the following way:
- If you use MSVC as compiler, open the correct Visual Studio Command Prompt. For example for VS2013 32-bit, click
Start -> Microsoft Visual Studio 2013 -> Visual Studio Tools -> VS2013 x86 Native Tools Command Prompt
. This will open a Command Prompt with theVCINSTALLDIR
environment variable correctly set.windeployqt.exe
requires this environment variable to copy the correct Visual C++ redistributable executable. - If you use MinGW, just open a Command Prompt.
- If you use MSVC as compiler, open the correct Visual Studio Command Prompt. For example for VS2013 32-bit, click
Add Qt binary path and optionally
g++.exe
path to PATH environment variable. If your executable is 32-bit, add the 32-bit Qt binary path, eg:c:\Qt\5.4\msvc2013\bin
. If your executable is 64-bit, add the 64-bit Qt binary path, eg:c:\Qt\5.4\msvc2013_64\bin
.windeployqt.exe
will copy DLLs from this directory, so it is important that you don't set 32-bit Qt binary path for a 64-bit executable, vice versa. You need to addg++.exe
path too if you use MinGW, windeployqt will copy lib*.dll from there.; Example path for MSVC 32-bit PATH=c:\Qt.4\msvc2013\bin;%PATH% ; Example path for MinGW 32-bit, g++.exe is in C:\Qt\Tools\mingw491_32\bin PATH=C:\Qt.4\mingw491_32\bin;C:\Qt\Tools\mingw491_32\bin;%PATH%
Run
windeployqt.exe
with your executable file as argument. Eg:windeployqt.exe C:\Qt\Examples\Qt-5.4\widgets\richtext\build-calendar-Desktop_Qt_5_4_0_MSVC2013_32bit-Debug\debug\calendar.exe
Check the output for error or warning. The following is an output without error and warning:
- 通过以下方式之一打开命令提示符:
- 如果您使用 MSVC 作为编译器,请打开正确的 Visual Studio 命令提示符。例如对于 VS2013 32 位,单击
Start -> Microsoft Visual Studio 2013 -> Visual Studio Tools -> VS2013 x86 Native Tools Command Prompt
。这将打开一个VCINSTALLDIR
正确设置环境变量的命令提示符。windeployqt.exe
需要此环境变量来复制正确的 Visual C++ 可再发行可执行文件。 - 如果您使用 MinGW,只需打开一个命令提示符。
- 如果您使用 MSVC 作为编译器,请打开正确的 Visual Studio 命令提示符。例如对于 VS2013 32 位,单击
添加 Qt 二进制路径和可选
g++.exe
路径到 PATH 环境变量。如果您的可执行文件是 32 位的,请添加 32 位 Qt 二进制路径,例如:c:\Qt\5.4\msvc2013\bin
. 如果您的可执行文件是 64 位,请添加 64 位 Qt 二进制路径,例如:c:\Qt\5.4\msvc2013_64\bin
.windeployqt.exe
将从该目录复制 DLL,因此重要的是不要为 64 位可执行文件设置 32 位 Qt 二进制路径,反之亦然。g++.exe
如果您使用 MinGW,您也需要添加路径,windeployqt 将从那里复制 lib*.dll。; Example path for MSVC 32-bit PATH=c:\Qt.4\msvc2013\bin;%PATH% ; Example path for MinGW 32-bit, g++.exe is in C:\Qt\Tools\mingw491_32\bin PATH=C:\Qt.4\mingw491_32\bin;C:\Qt\Tools\mingw491_32\bin;%PATH%
运行
windeployqt.exe
你的可执行文件作为参数。例如:windeployqt.exe C:\Qt\Examples\Qt-5.4\widgets\richtext\build-calendar-Desktop_Qt_5_4_0_MSVC2013_32bit-Debug\debug\calendar.exe
检查输出是否有错误或警告。以下是没有错误和警告的输出:
2. Manually copy the DLLs
2.手动复制DLL
You must copy the correct DLLs (32-bit or 64-bit). Use a tool like Process Explorerto find the correct DLL paths:
您必须复制正确的 DLL(32 位或 64 位)。使用Process Explorer 之类的工具找到正确的 DLL 路径:
- Run the application from Qt Creator / Visual Studio.
- Open Process Explorer.
- In Process Explorer
- Click the executable, for example
calendar.exe
- Press
Ctrl+D
to show loaded DLLs in the lower panel. The equivalent menu isView -> Lower Panel View -> DLLs
- In the lower panel, click the
Path
column to sort by path.
- Click the executable, for example
- Copy the DLLs to the directory where the executable resides. For example in the following picture. The DLLs are from C:\Qt\5.4\msvc2013\bin.
- 从 Qt Creator / Visual Studio 运行应用程序。
- 打开进程资源管理器。
- 进程内浏览器
- 单击可执行文件,例如
calendar.exe
- 按下
Ctrl+D
可在下方面板中显示加载的 DLL。等效菜单是View -> Lower Panel View -> DLLs
- 在下方面板中,单击
Path
列以按路径排序。
- 单击可执行文件,例如
- 将 DLL 复制到可执行文件所在的目录。例如在下图中。DLL 来自 C:\Qt\5.4\msvc2013\bin。
- If your executable uses something like
c:\Qt\5.4\msvc2013\plugins\platforms\qwindowsd.dll
. It should be copied too. But copy from theplatforms
directory, notplugins
. Let's saycalendar.exe
's full path isc:\examples\calendar.exe
, thenqwindowsd.dll
should be copied toc:\examples\platforms\qwindows.dll
, notc:\examples\plugins\platforms\qwindows.dll
. You need to copy C++ runtime library too. If you are using mingw, you may need to copy
libgcc_s_dw2-1.dll
,libstdc++-6.dll
.libwinpthread-1.dll
etc too. Check in Process Explorer to be sure. If you are using MSVC, you need to deploy the runtime (Eg:msvcp120.dll
,msvcr120.dll
). At the end, your directory structure is something like this:c:\examples\calendar.exe c:\examples\Qt5Cored.dll c:\examples\Qt5Widgetsd.dll c:\examples\Qt5Guid.dll c:\examples\icudt53.dll c:\examples\icuin53.dll c:\examples\icuuc53.dll c:\examples\libgcc_s_dw2-1.dll (if using mingw) c:\examples\libstdc++-6.dll (if using mingw) c:\examples\libwinpthread-1.dll (if using mingw) c:\examples\platforms\qwindowsd.dll
- 如果您的可执行文件使用类似
c:\Qt\5.4\msvc2013\plugins\platforms\qwindowsd.dll
. 它也应该被复制。但是从platforms
目录复制,而不是plugins
. 假设的calendar.exe
完整路径是c:\examples\calendar.exe
,那么qwindowsd.dll
应该复制到c:\examples\platforms\qwindows.dll
,而不是c:\examples\plugins\platforms\qwindows.dll
。 您还需要复制 C++ 运行时库。如果您使用的是 mingw,则可能需要复制
libgcc_s_dw2-1.dll
,libstdc++-6.dll
.libwinpthread-1.dll
等等。检查进程资源管理器以确保。如果您使用 MSVC,则需要部署运行时(例如:msvcp120.dll
、msvcr120.dll
)。最后,你的目录结构是这样的:c:\examples\calendar.exe c:\examples\Qt5Cored.dll c:\examples\Qt5Widgetsd.dll c:\examples\Qt5Guid.dll c:\examples\icudt53.dll c:\examples\icuin53.dll c:\examples\icuuc53.dll c:\examples\libgcc_s_dw2-1.dll (if using mingw) c:\examples\libstdc++-6.dll (if using mingw) c:\examples\libwinpthread-1.dll (if using mingw) c:\examples\platforms\qwindowsd.dll
回答by DrumM
A simple solution for me was just adding the QTDIR C:\Qt\5.4\msvc2017_64\ to your Windows system variables.
对我来说一个简单的解决方案是将 QTDIR C:\Qt\5.4\msvc2017_64\ 添加到您的 Windows 系统变量中。
- In Windows search, type 'env' and press "Edit the system environment variables"
- Press "Environment Variables" below
- In the System variables list, press "New..."
- Add
QTDIR
as variable name, with value the directory name of the compiler under the Qt directory:C:\Qt\5.4\mingw491_32
in your case
- 在 Windows 搜索中,输入“env”并按“编辑系统环境变量”
- 按下面的“环境变量”
- 在系统变量列表中,按“新建...”
- 添加
QTDIR
为变量名,值为Qt目录下编译器的目录名:C:\Qt\5.4\mingw491_32
在你的情况下
回答by StndFish
The answer given by fxamis an in-depth, comprehensive one. I have tried the approaches provided and they work!
fxam给出的答案是深入、全面的。我已经尝试了提供的方法并且它们有效!
Just add a comment that in case of MinGW64, one should run windeplyqt.exe in the directory of "C:\Qt\Qt5.13.1\5.13.1\mingw73_64\bin".
只需添加一条注释,在MinGW64的情况下,应在“C:\Qt\Qt5.13.1\5.13.1\mingw73_64\bin”目录中运行windeplyqt.exe。
DrumM's answer is the simplest solution. It has been mentioned as 1.2. in fxam's answer though.
DrumM的答案是最简单的解决方案。它已被提及为 1.2。不过在fxam的回答中。