Visual Studio packages source files as executable .exe programs (with Qt Tool and third-party libraries)

Written in the front:
The reason for looking for this packaging method is that I used Qt to write a big homework. In order to package the program, I found a lot of content from ChatGPT and the Internet. It took almost a day to package it. The following is During the packaging process, I used Obsidian to remember some

After the packaging is completed, you can send the program to your classmates' computers, so that the programs you write can be executed on their computers.

The Visual Studio I use is Visual Studio 2019 and the extension of the corresponding downloaded QT VS Tools to connect Qt to develop desktop applications (Qt Widgets Application). In addition, in the project, third-party libraries (Eigen, Boost, CGAL ), so it will be more troublesome to pack.

In addition, let me explain that I have also seen the use of Visual Studio Installer to package Visual Studio programs into exe files , but because I have many third-party libraries and have Qt dependencies, there is no way to directly add source files.

Specifically, it is actually packaged directly using the Release function in Visual Studio.


First of all, let me explain that in Qt 6.5.0, an error will occur when installing the packaging program. I checked on the Internet and found that this is the internal reason of version 6.5.0. If you are using version 6.5.0, please uninstall and reinstall 6.5 .1 version for packager


packaging steps

To package a project with Qt extensions in Visual Studio 2019 as an executable .exe file, the following steps need to be followed:

  1. In Visual Studio, in Solution Explorer, right-click on the project and select Properties. In the Configuration drop-down menu, select Release.
    insert image description here

  2. Make sure the project is properly configured, including additional include paths and libraries. In the project properties, go to "C/C++" -> "General" and check that "Additional Include Directories" contains paths to Qt header files and third-party libraries. Then go to "Linker" -> "General", check whether "Additional Library Directory" contains the path of Qt library and third-party library (you need to include the include and lib path of the third-party library you use, and the program can run normally. If it is a library configured with NuGet, skip it) (This step is generally done if your program can run normally and there is no absolute path inclusion item)

  3. Use windeployqt to select Run Deployment in the Qt Project Settings in the Project properties to Yes (the default is No) (the Run Deployment Tool option in the figure below should be changed to Yes)

  • Note: In order to ensure the normal operation of windeployqt, it needs to be E:\Qt\6.5.1\msvc2019_64\binadded to the system environment variable Path, and the corresponding windeployqt tool is valid

In addition, how to test whether the windeployqt of the project is successful: Build the solution first, and then you will find the .exe file under the x64/Debug or Release folder of the project (if it is not changed according to 4, it is the Debug folder), at this time , in the corresponding folder

windeployqt FriskFEM.exe     // FriskFEM换成你的可执行文件exe

If no error is reported, it means that there is basically no problem. If windeployqt is not found, please configure the path according to the above instructions. If it is abnormally terminated, then your Qt may be version 6.5.0, please uninstall and reinstall 6.5.1 version is packaged.

  1. Then right-click the solution, select Configuration Properties in the configuration box, and then open the Configuration Properties in the upper right corner. At this time, your Configuration Manager may still be Debug. At this time, please make sure to set your program to Release (all require Release), As shown in the figure below
    insert image description here
    , it should be noted that if you uninstall and reinstall Qt, you may find that the project cannot find Qt after the overall configuration of the project is converted to Release. Please select it again in Project -> Properties -> Qt Installation The version of Qt you need.
    insert image description here
  2. Select the output directory of the project:
    In the project configuration (Project-> Properties) -> Qt Deploy Tool -> Debug/Release Binaries, change the corresponding option to Release
    insert image description here
  3. Build the project again. In Solution Explorer, right-click on the project and choose Build Solution.
    insert image description here
    Then you will see the Release path in the x64 folder of the project (usually under the same path as the .sln file) Open the Release folder,
    insert image description here
    the project is as shown in the figure:
    insert image description here
    Note that the parts inside are Qt6Gui and Qt6Widgets.dll, etc. , if it is Qt6Guid, then the Debug/Release Binaries in the above step is not set

Next, the packaging is successful. At this time, you can directly compress the Release folder and send it to others, and the program can run on other people's computers.


Although this issue is still quite good (and it is also the exam week), in fact, in order for Cheng Xun to run normally, the author tested it seven or eight times on computers including roommates and other students before running successfully. Program debugging It’s not easy, if this article is helpful to you, I still hope to give this article a thumbs up before leaving!

Guess you like

Origin blog.csdn.net/sbsbsb666666/article/details/131208056