2013年2月4日星期一

將一個小型 Qt5 Win32 (MSVC 版本) 程序放到另一台電腦上

要將一個小型 Qt5 Win32 (MSVC 版本) 程序放到另一台電腦上執行, 除了程序本身外, 我們也需要複製以下 DLL:

icudt49.dll (在 ICU 49 套件內)
icuin49.dll (在 ICU 49 套件內)
icuuc49.dll (在 ICU 49 套件內)
libEGL(d).dll (在 Qt5 的資料夾內的 msvc2010\lib 內)
libGLESv2(d).dll (在 Qt5 的資料夾內的 msvc2010\lib 內)
msvcp100(d).dll (在 Windows 的 System32 內)
msvcr100(d).dll (在 Windows 的 System32 內)
Qt5Core(d).dll (在 Qt5 的資料夾內的 msvc2010\lib 內)
Qt5Gui(d).dll (在 Qt5 的資料夾內的 msvc2010\lib 內)
Qt5Widgets(d).dll (在 Qt5 的資料夾內的 msvc2010\lib 內)
/platforms/qminimal(d).dll (在 Qt5 的資料夾內的 msvc2010\plugins\platforms 內)
/platforms/qwindows(d).dll (在 Qt5 的資料夾內的 msvc2010\plugins\platforms 內)

(d) 代表 debug 版本

留意 qminimal 和 qwindows 必須放在 platforms 子資料夾內, 否則程序會報錯.

安裝 Qt5 for Win32 (MSVC 2010 版本)

在安裝 Qt5 for Windows 32 bit (VS 2010 Version) 之前, 我們需要先安裝以下軟件:

1. Microsoft Visual C++ Express 2010
這裡下載 Microsoft Visual C++ Express 2010 並安裝, 然後再安裝有關 Patch 和 Service Pack.
因為我們需要 VC++ 的 Compiler 和 Linker.

2. Windows Software Development Kit (SDK)
這裡下載 Windows SDK, 然後安裝有關 Debugger (CDB) 的軟件

3. 由於 Qt Core 會用 ICU 的 DLL, 如果你需要將你的程序放到其他電腦上執行的話, 那麼請下載 IUC 49 套件.

4. 完成上面的步驟後便可以安裝 Qt5 for Windows (VS 2010)

5. 當然, 如果你需要將你的程序放到其他電腦上執行的話, Dependency Walker 一定少不了


[轉貼] How can an MSVC program call an MinGW DLL, and vice versa?

轉貼一個在 Windows 32 platform 下用 MinGW 和 MS VC DLL 的技巧
原文

Q. How can an MSVC program call an MinGW DLL, and vice versa?
A. Assume we have a testdll.h, testdll.c, and testmain.c. In the first case, we will compile testdll.c with MinGW, and let the MSVC-compiled testmain call it. You should use
gcc -shared -o testdll.dll testdll.c \
    -Wl,--output-def,testdll.def,--out-implib,libtestdll.a
to produce the DLL and DEF files. MSVC cannot use the MinGW library, but since you have already the DEF file you may easily produce one by the Microsoft LIB tool:
lib /machine:i386 /def:testdll.def
Once you have testdll.lib, it is trivial to produce the executable with MSVC:
cl testmain.c testdll.lib
Now for MinGW programs calling an MSVC DLL. We have two methods. One way is to specify the LIB files directly on the command line after the main program (in newer MinGW versions; MinGW GCC 2.95.2 is reported not to work). For example, after
cl /LD testdll.c
use
gcc -o testmain testmain.c testdll.lib
The other way is to produce the .a files for GCC. For __cdecl functions (in most cases), it is simple: you only need to apply the reimp tool (the original site is unavailable now, but you may download here a version enhanced by José Fonseca):
reimp testdll.lib
gcc -o testmain testmain.c -L. -ltestdll
However, the above method does not work with __stdcall functions. For MSVC will prefix an underscore to __stdcall functions while MinGW will not. The right way is to produce the DEF file using the pexports tool (downloadable here if not found elsewhere) and filter off the first underscore by sed:
pexports testdll.dll | sed "s/^_//" > testdll.def
Then, when using dlltool to produce the import library, add `-U' to the command line:
dlltool -U -d testdll.def -l libtestdll.a
And now, you can proceed in the usual way:
gcc -o testmain testmain.c -L. -ltestdll
Hooray, we got it. And that is the end of this FAQ.
2001-12-21, written by Wu Yongwei
2004-7-29, last revised by Wu Yongwei