Code::Block + MinGW + wxWidgets开发Windows GUI程序
开发环境:
Windows 7
MinGW中gcc版本:4.6.2
Code::Block版本:10.05
wxWidgets版本:2.8.12
1. 编译wxWidgets
设置Mingw的bin目录为系统的Path环境变量之一。
wxWidgets安装到E:\下,输入命令
cd E:\wxWidgets-2.8.12\build\msw
mingw32-make -f makefile.gcc BUILD=release UNICODE=1
mingw32-make -f makefile.gcc BUILD=debug UNICODE=1
可以不编译debug版本,但建议生成debug库以便调试,UNICODE=1指定了编译出来的wxWidgets库支持UNICODE。
编译完成需要大概半个小时.
2.使用Code:Blocks开发wxWidgets
打开Code::Blocks,新建一个wxWidgets项目。
选择wxWidgets 2.8.x,输入项目名称。
在选择wxWidgets目录时,填写E:\wxWidgets-2.8.12,下一步会出一个窗口设置Global variables,也可以从Settings下面的菜单进入。
设置Global variables:
新建环境变量wx,它的设置如下:
Base: 指向E:\wxWidgets-2.8.12
include:指向E:\wxWidgets-2.8.12\include
lib:E:\wxWidgets-2.8.12\lib
然后点Close,在后面勾上Enable Unicode。
打开Code::Block的编译器设置页,在Search directories标签页中填写以下信息:
Complier
$(#wx.include)
$(#wx.lib)\gcc_lib\mswu
$(#wx)\contrib\include
Linker
$(#wx.lib)\gcc_lib
$(#wx)\build\msw\gcc_mswu
点击编译并运行。
3.解决问题:
a.如果编译应用程序出现下面的错误,则是使用的gcc与编译wxWidgets的不一样。
undefined reference to `_Unwind_Resume'
b. 单独运行编译后的文件出现“libgcc_s_dw2-1.dll is missing”
this is a MinGW/gcc compiler issue, rather than a Microsoft Visual Studio setup.
The libgcc_s_dw2-1.dll should be in the compiler's bin directory. You can add this directory to your PATH environment variable for runtime linking, or you can avoid the problem by adding "-static-libgcc -static-libstdc++" to your linker flags.
If you plan to distribute the executable, the latter probably makes the most sense. If you only plan to run it on your own machine, the changing the PATH environment variable is an attractive option (keeps down the size of the executable).
Settings -- Compiler and debugger -- Global Compiler settings -- Linker settings, 在'other linker options'中加如下2行
-static-libgcc
-static-libstdc++
4. 其他
GUI布局设计可以使用wxFormBuilder或者wxSimth.
编译一个code blocks自带的wxWidgets sample代码,debug版本的可执行文件大小为27.49MB, Release版本的可执行文件大小为1.95MB.
5. 参考
.http://www.cnblogs.com/zimmerk/archive/2012/06/07/2541082.html
.http://stackoverflow.com/questions/4702732/the-program-cant-start-because-libgcc-s-dw2-1-dll-is-missing
开发环境:
Windows 7
MinGW中gcc版本:4.6.2
Code::Block版本:10.05
wxWidgets版本:2.8.12
1. 编译wxWidgets
设置Mingw的bin目录为系统的Path环境变量之一。
wxWidgets安装到E:\下,输入命令
cd E:\wxWidgets-2.8.12\build\msw
mingw32-make -f makefile.gcc BUILD=release UNICODE=1
mingw32-make -f makefile.gcc BUILD=debug UNICODE=1
可以不编译debug版本,但建议生成debug库以便调试,UNICODE=1指定了编译出来的wxWidgets库支持UNICODE。
编译完成需要大概半个小时.
2.使用Code:Blocks开发wxWidgets
打开Code::Blocks,新建一个wxWidgets项目。
选择wxWidgets 2.8.x,输入项目名称。
在选择wxWidgets目录时,填写E:\wxWidgets-2.8.12,下一步会出一个窗口设置Global variables,也可以从Settings下面的菜单进入。
设置Global variables:
新建环境变量wx,它的设置如下:
Base: 指向E:\wxWidgets-2.8.12
include:指向E:\wxWidgets-2.8.12\include
lib:E:\wxWidgets-2.8.12\lib
然后点Close,在后面勾上Enable Unicode。
打开Code::Block的编译器设置页,在Search directories标签页中填写以下信息:
Complier
$(#wx.include)
$(#wx.lib)\gcc_lib\mswu
$(#wx)\contrib\include
Linker
$(#wx.lib)\gcc_lib
$(#wx)\build\msw\gcc_mswu
点击编译并运行。
3.解决问题:
a.如果编译应用程序出现下面的错误,则是使用的gcc与编译wxWidgets的不一样。
undefined reference to `_Unwind_Resume'
b. 单独运行编译后的文件出现“libgcc_s_dw2-1.dll is missing”
this is a MinGW/gcc compiler issue, rather than a Microsoft Visual Studio setup.
The libgcc_s_dw2-1.dll should be in the compiler's bin directory. You can add this directory to your PATH environment variable for runtime linking, or you can avoid the problem by adding "-static-libgcc -static-libstdc++" to your linker flags.
If you plan to distribute the executable, the latter probably makes the most sense. If you only plan to run it on your own machine, the changing the PATH environment variable is an attractive option (keeps down the size of the executable).
Settings -- Compiler and debugger -- Global Compiler settings -- Linker settings, 在'other linker options'中加如下2行
-static-libgcc
-static-libstdc++
4. 其他
GUI布局设计可以使用wxFormBuilder或者wxSimth.
编译一个code blocks自带的wxWidgets sample代码,debug版本的可执行文件大小为27.49MB, Release版本的可执行文件大小为1.95MB.
5. 参考
.http://www.cnblogs.com/zimmerk/archive/2012/06/07/2541082.html
.http://stackoverflow.com/questions/4702732/the-program-cant-start-because-libgcc-s-dw2-1-dll-is-missing