2010-05-22 0: 53
In fact, the Manual of QT has clearly explained this problem. The following is what I wrote based on my understanding and experiment. I hope it is easier to understand than the QT document.
In addition, you may be interested in learning the QT plug-in (1. If you need to create and installProgram, Please visit NSIs Study Notes (taking qt4 program as an example)
Static compilation is not involved below (static compilation can be viewed here). It only includes dynamic compilation (that is, the default situation of QT), which is mainly divided into mingw and msvc:
Mingw
First, we need to generate the release mode executable program (many complained,A small program requires more than 100 MB of dynamic libraries.Because debug is used)
Qmake
Mingw32-make release
Then, place the executable file and the required dynamic library in the same folder.
- Myprogram.exe
- Mingwm10.dll
- Libgcc_s_dw2-1.dll
- Qtcore4.dll
- Qtgui4.dll
Some complained that the Program reported an error after the dynamic library was copied.Unable to locate program Input Point on the Dynamic Link Library qtcore4.dllThis is generally because multiple QT runtime libraries are installed in the system, and you are not copying the libraries in the QT installation directory. For example, when the qt sdk is installed, it is easy to cause this problem because the QT in it is compiled by mingw, but the qtcreator in it is compiled by msvc, so many people accidentally copied the QT Runtime Library with qtcreator.
If you don't need other plug-ins, you can release the program. However, many people complainImages in JPG, GIF, and BMP formats cannot be displayed.This is because QT native supports PNG, while other formats need to be supported by plug-ins (the plug-ins are under the % qtdir %/plugins \ imageformats directory)
You only need to copy the required plug-in to the imageformats directory in the directory where the executable program is located.
- Myprogram.exe
- Imageformats \ q00004.dll
- Imageformats \ qgif4.dll
- ...
Similarly, if your programSupport for gb2312 and GBK EncodingTo copy the corresponding plug-ins under the % qtdir % \ plugins \ codecs directory to the codecs directory where the executable program is located.
- Myprogram.exe
- Codecs \ qcncodecs4.dll
- ...
Suggestion: Check the Plugins directory under the QT installation directory to familiarize yourself with what these plug-ins are and what programs you need to release.
Now, the program can be released. Now you can also use NSIs to create an installation package (NSIS Study Notes (taking qt4 program as an example )).
Msvc
If vs2008 is used instead of mingw, the release process is basically the same.
First, generate the release mode Executable File
Qmake
Nmake release
Then prepare the required dynamic library and plug-ins.
- Myprogram.exe
- Qtcore4.dll
- Qtgui4.dll
- Imageformats \ * 4.dll
- ...
Because it is VC compiled, so do not need mingw mingwm10.dll libgcc_s_dw2-1.dll, replace them with vc2008 C \ c ++ Runtime Library:
If you use a Windows XP system, you only need to put the two runtime libraries and executable programs in the same directory.
However, for Windows XP (including) systems, this will not work normally and the program will report:The application fails to start because the application configuration is incorrect.. This problem is a bit complicated. In fact, the solution is very simple. You only need to install the vcredist_x86.exe package of vs2008 with more than 1 MB on your machine.
This package will install the Runtime Library to the winsxs directory under the window system directory. For systems earlier than XP, The Runtime Library will also be installed to the directory under the path at the same time. In fact, if the user has installed the vc2008 program compiled by others, the package should have been installed on the machine.
You may want to ask what to do if you don't want to install a redistributable package. For example, if you want to package a DLL and a program, we can do this:
Folder (if vs2008 Express is used, this folder does not exist)
<Visual Studio install path> \ Vc \ redist \ <architecture> \ microsoft. vc90.crt
Directly copy to the directory where the executable program is located
- Myprogram.exe
- Microsoft. vc90.crt \*
Note:
- If you have installed a redistributable package on your machine, the program will never use the library under Microsoft. vc90.crt.
- When this method is used, if the plug-in (including image plug-ins) is released at the same time, the plug-in compilation must be:
Config-= embed_manifest_dll
So that the generated plug-in does not embed the manifest file, otherwise the plug-in is not recognized by the Program (in fact, it can also be identified, as long as Microsoft. copy a copy of vc90.crt and put the plug-in the same folder. Of course, this method is not good. If the plug-in is distributed in several directories, you need to place Microsoft. vc90.crt ).
Tools
1. Be sure to remember: dependency Walker is a good helper for you. It will tell you which libraries your EXE and DLL need, and the folder in which the dynamic libraries it loads are stored.
2. It is best to prepare a tool for viewing processes, such as Microsoft process explorer, to check which dynamic libraries are loaded by your program (which plug-ins are loaded)