Code::Block + MinGW + wxWidgets開發Windows GUI程式

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.