[zhuan] linux 下 wxWidgets 安裝,編譯

 
http://blog.csdn.net/yuzhenxiong0823/article/details/7727133
wxWidgets在Linux下有wxGTK和wxX11供使用,各須要GTK和X11開發環境; 

wxWidgets在linux下有wxGTK和wxX11供使用,可是分別須要配置GTK和X11開發環境,開發環境配置以下:linux

X11的安裝(若是選擇使用wxX11):shell

apt-get install libx11-devthis

GTK的安裝(若是選擇使用wxGTK):spa

apt-get install gnome-core-devel #這將安裝 libgtk2.0-dev libglib2.0-dev 等開發相關的庫文件.net

www.wxwidgets.org裏下載wxGTK或wxX11,這就是wxWidgets的庫,下面是編譯方法,以wxGTK爲例:blog

tar -zxf wxGTK-2.8.11.tar.gz開發

cd wxGTK-2.8.11get

./configure編譯器

makeit

sudo make install

sudo ldconfig

輸入wx-config --cxxflags,檢查wxGTK是否正確配置安裝

若是能看到wx-config頭文件的路徑就說明已經配置成功了。

 

下面我舉個例子,說明下如何使用wx-config進行wxGTK程序的編譯

hello.cpp 內容以下:

#include "wx/wx.h"

class HelloWorldApp : public wxApp
{
public:
    virtual bool OnInit();
private:
    wxButton *button;
};


IMPLEMENT_APP(HelloWorldApp)

/* this is executed upon startup, like 'main()' in non-wxWidgets programs */

bool HelloWorldApp::OnInit()
{
    wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Hello wxWidgets World"));
    frame->CreateStatusBar();
    frame->SetStatusText(_T("Hello World"));
    button = new wxButton((wxFrame *)frame, -2, _T("123"));
    frame->Show(TRUE);
    SetTopWindow(frame);

    return true;
}

執行編譯:
$(wx-config  --cxx)  hello.cpp  $(wx-config  --libs  --cxxflags)  -o  hello
執行程序:
./hello

就能夠看到wxGTK的窗口了,感受還能夠的,我就不貼圖了,更關鍵的是,有了wx-config,makefile編寫也簡單了不少,咱們能夠在makefile經過執行shell來獲取包含文件和庫文件信息,如咱們能夠在makefile的開頭這樣寫

cxx:=$(shell wx-config --cxx)

libs:=$(shell wx-config --libs)

cxxflags:=$(shell wx-config --cxxflags)

在後面能夠直接使用cxx做爲編譯器,用libs做爲鏈接庫,用cxxflags做爲包含庫使用了,不過用的時候別忘記使用$(cxx)、$(libs) 和$(cxxflags),這樣makefile的編寫也簡單了不少。具體的makefile這裏就不寫了,仍是相信你懂得。

相關文章
相關標籤/搜索