上个周末在研究 wxWidgets 的环境搭建, linux 下由于有 wx-config ,很快就搞定,但 windows 下想要编译出不依赖 visual studio 2005 的可执行文件花了不少时间。
特将过程记录 如下,以防日后忘却,再花冤枉时间。
1. 什么是 wxWidgets
wxWidgets lets developers create applications for Win32, Mac OS X, GTK+, X11, Motif, WinCE, and more using one codebase. It can be used from languages such as C++, Python, Perl, and C#/.NET . Unlike other cross-platform toolkits, wxWidgets applications look and feel native . This is because wxWidgets uses the platform's own native controls rather than emulating them. It's also extensive, free, open-source, and mature . Why not give it a try, like many others have ?
2. Visual Studio 2005 下 wxWidgets 的下载、安装与配置
a) 下载: 去 http://wxwidgets.org/downloads/ 下载 wxMSW 版本的 wxWidgets ,下载下来的应该是一个 exe 的安装文件。
b) 安装: 运行下载下来的安装文件,安装在 D:/wxWidgets-2.8.0 目录 中。
c) 编译 Debug 版本的库: 用 Visual Studio 2005 打开 build/msw/wx.dsw 文件, Solution Configurations 中选中 Unicode Debug ,直接 Build Solution 就可以编译出 Debug 版本的 wxWidgets 库了。
d) 编译 Relase 版本的库: Release 版本的 wxWidgets 库虽然也可以通过类似的 方法去编译,但编译出来的库仍然依赖于 visual studio 2005 的运行时库。 Debug 版本的库依赖 VS2005 也就算了,反正是自己调试用的。 Release 版本可是要给别人用的,再带上一大堆 dll 就不好了。为了解决这个问题,我们需要先在 Solution Configuration 中选中 Unicode Release ,然后在 Solution Explorer 中,针 对每一个 project 在项目属性的 C/C++ --> Code Generation --> Runtime Library 中选 Multi-Threaded 。 (HOHO, 有 20 个项目要改属性啊 ~~~) 。最后再 Build Solution 就可以了。
关于不同的 Runtime Library 的信息,可参见:
e) Visual Studio 2005 的配置:
打开 Tools --> Options --> Projects and Solutions --> VC++ Directories
i. 在 Include files 中加入 D:/wxWidgets-2.8.0/include
ii. 在 Library files 中加入 D:/wxWidgets-2.8.0/lib/vc_lib
f) 基于 wxWidgets 的项目的配置:
打开项目属性
i. Debug 版本的配置:
C/C++ --> General --> Additional Include Directories 中写入: D:/wxWidgets-2.8.0/lib/vc_lib/mswud
C/C++ --> Code Generation --> Runtime Library 选 Multi-Threaded Debug DLL
Linker --> Input --> Additional Dependencies 写入: wxmsw28ud_core.lib wxbase28ud.lib wxtiff.lib wxjpeg.lib wxpng.lib wxzlib.lib wxregexu.lib wxexpat.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib odbc32.lib
Linker --> Input --> Ignore Specific Library 写入: LIBCMTD.lib
ii. Release 版本的配置:
C/C++ --> General --> Additional Include Directories 中写入: D:/wxWidgets-2.8.0/lib/vc_lib/mswu
C/C++ --> Code Generation --> Runtime Library 选 Multi-threaded
Linker --> Input --> Additional Dependencies 写入: wxmsw28u_core.lib wxbase28u.lib wxtiff.lib wxjpeg.lib wxpng.lib wxzlib.lib wxregexu.lib wxexpat.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib odbc32.lib
wxWidgets 的跨平台性,实现 i18n 的便利性以及功能的完备性让我越来越感兴趣。预计今后几年的 GUI 开发都将会基于 wxWidgets 了。
Farewell, MFC! Don’t cry for me, Microsoft! :)