C++ 如何在 Qt Creator 中制作 .exe 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25570752/
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
How to make .exe file in Qt Creator
提问by Sarwan Pasha
I was working on Qt Creator compiler to make a simple text editor. I did that but now want to make an .exe
file of that project, but I don't know how to make an .exe
file in Qt Creator compiler. Can anyone help?
我正在使用 Qt Creator 编译器来制作一个简单的文本编辑器。我这样做了,但现在想制作.exe
该项目的文件,但我不知道如何.exe
在 Qt Creator 编译器中制作文件。任何人都可以帮忙吗?
回答by Andrew T
There is a tool that adds the .dlls automatically on windows.
有一个工具可以在 Windows 上自动添加 .dll。
In the command prompt navigate to your qt bin directory. It should look something like this: ...\Qt\5.9.1\msvc2017_64\bin\ (I'm using visual studio).
在命令提示符中导航到您的 qt bin 目录。它应该看起来像这样:...\Qt\5.9.1\msvc2017_64\bin\(我正在使用 Visual Studio)。
Run windeployqt.exe in the command prompt with your project location as the argument like this:
在命令提示符中运行 windeployqt.exe,使用您的项目位置作为参数,如下所示:
windeployqt.exe C:\project_folder\my_project.exe
windeployqt.exe C:\project_folder\my_project.exe
Now my_project.exe
will have the .dlls in the same directory and will execute.
现在my_project.exe
将在同一目录中拥有 .dll 并将执行。
回答by Forcetti
From: How to create executable file for a Qt Application?Basically you have to look for MinGW subfolder deep into Qt tree, where Qt utilities reside, and copy needed dll's.
来自: 如何为 Qt 应用程序创建可执行文件?基本上,您必须在 Qt 树的深处寻找 MinGW 子文件夹,Qt 实用程序所在的位置,并复制所需的 dll。
These are the steps I follow, based upon Qt 4.7.4, for packaging the application with correct shared libraries.
这些是我遵循的步骤,基于 Qt 4.7.4,用于使用正确的共享库打包应用程序。
Let's say you've installed Qt under c:\qtsdk. Open your project, and compile it in release mode. Go to this directory: C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin -- it contains all shared libraries. Debug libraries end with a "d" -- frex, QtCore.dll is release version, while QtCoreD.dll is debug version. Copy at least these files into your release directory (where your .exe lies):
假设您已经在 c:\qtsdk 下安装了 Qt。打开您的项目,并在发布模式下编译它。转到这个目录:C:\QtSDK\Desktop\Qt\4.7.4\mingw\bin——它包含所有共享库。调试库以“d”结尾——frex,QtCore.dll 是发布版本,而 QtCoreD.dll 是调试版本。至少将这些文件复制到您的发布目录(您的 .exe 所在的位置):
- mingwm10.dll
- libgcc_s_dw2-1.dll
- QtCore4.dll
- QtGui4.dll
- mingwm10.dll
- libgcc_s_dw2-1.dll
- QtCore4.dll
- QtGui4.dll
I just built, tested and deployed a dummy project this way.
我刚刚以这种方式构建、测试和部署了一个虚拟项目。
回答by zeFrenchy
The executable is generated by the compiler when you build your application. To know where the executable is stored, look into
可执行文件是在您构建应用程序时由编译器生成的。要知道可执行文件的存储位置,请查看
Projects (CTRL+5) -> Build settings -> General -> Build directory
Projects (CTRL+5) -> Build settings -> General -> Build directory
This is where Qt creator will put the .exe it generates if you have shadow build enabled. If shadow build is disabled, the executable will be stored inside the project folder itself.
如果您启用了影子构建,Qt 创建者将在此处放置它生成的 .exe。如果禁用影子构建,则可执行文件将存储在项目文件夹本身中。