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