2009-07-18

wxWidgets でもクロスコンパイル(2)

Get MinGW Cross Compiler at SourceForge.net. Fast, secure and Free Open Source software downloads

Fedora 11 から Win32 クロスコンパイル用パッケージが正式にサポートされるようになって、自分の SourceForge.net のプロジェクトサイトで、クロスコンパイル用 RPM パッケージの公開に対するモチベーションが下がってしまい、活動が低調になっていました。

とあるユーザから、wxWidgets 用の RPM を Fedora 11 用にも公開してほしいというメールを受け取りました。

Date: Thu, 16 Jul 2009 14:51:21 +0200
Subject: mingw-wxwidgets on fedora11?
From: ##### ######### <#####.########@gmail.com>
To: bitwalk at users.sourceforge.net

Dear ####### #########,

I've succesfully used your rpm packaging of mingw32-wxWidgets on fedora 10
(mingw32-wxWidgets-2.8.9-2.fc10.noarch.rpm), it was really helpful to me in
developing a cross-platform application that I need to mantain. So much
important that the only thing that I'm actually waiting for before
switching to fedora11 is exactly the release of the same package for
fedora11. So I would like to ask you if you have any plan to release such
package for fedora11, or if there is any way that I can use the f10
package on fedora11.

Thank you very much for your attention and many thanks for your great work,
##### ########

wxWidgets の RPM パッケージについては、Fedora MinGW のメーリングリストで話題が出ていたので、きっと誰かが作るだろうと放っておいたのでした。しかし、直接メールを送ってくれるユーザがいれば話は別です。返事を出して早速パッケージを作成しました。

Browse MinGW Cross Compiler Files on SourceForge.net
- mingw32-wxWidgets-2.8.10-1.fc11.noarch.rpm
- mingw32-filesystem-50-3.fc11.2.noarch.rpm

このサイトで公開した mingw32-filesystem は、wxWidgets のファイルの依存性を解決するために必要になります。

以前、「wxWidgets でもクロスコンパイル」で紹介したサンプルを再掲して、現在の環境に合わせたクロスコンパイル方法を紹介します。サンプルは以下をベースにしています。

Hello World - wxWidgets

表示される文字列を日本語にした他は、同じプログラムです。

// Hello World program with wxWidgets
#include "wx/wx.h"

class MyApp: public wxApp
{
virtual bool OnInit();
};

class MyFrame: public wxFrame
{
public:

MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);

DECLARE_EVENT_TABLE()
};

enum
{
ID_Quit = 1,
ID_About,
};

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(_T("こんにちは、世界!"),
wxPoint(50,50), wxSize(450,340));
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;

menuFile->Append(ID_About, _T("このプログラムについて(&A)"));
menuFile->AppendSeparator();
menuFile->Append(ID_Quit, _T("終了(&x)"));

wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, _T("ファイル(&F)"));

SetMenuBar(menuBar);

CreateStatusBar();
SetStatusText(_T("wxWidgets へようこそ!"));
}

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(_T("はじめてのプログラム、こんにちは、世界!"),
_T("このプログラムについて"), wxOK | wxICON_INFORMATION, this);
}
// END PROGRAM
// hello.cpp


コンパイルには、Linux の pkg-config を利用するので、MinGW のバイナリがインストールされている /usr/i686-pc-mingw32/sys-root/mingw/bin へパスを通しておきます。もし、Linux 用の wxWidgets もインストールされている場合には、検索パスを順序も含めて適正に指定するか、pkg-config の代わりに MinGW クロスコンパイル用の i686-pc-mingw32-pkg-config を利用すればいいでしょう。

$ export PATH=$PATH:/usr/i686-pc-mingw32/sys-root/mingw/bin
$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/bin:/usr/b
in:/usr/local/sbin:/usr/sbin:/sbin:/home/bitwalk/bin:/opt/mingw32ce/bin:/usr/i68
6-pc-mingw32/sys-root/mingw/bin

$ i686-pc-mingw32-g++ hello.cpp `wx-config --libs` `wx-config --cxxflags`
-o hello.exe


wbc で、ビルドした hello.exe が依存する DLL を調べると、次の様になります。




Wine


Wine 上で実行した例を示しました。

$ ./hello.exe


Windows


関連する DLL と一緒に Windows Vista へコピーして実行すると以下の様になります。とりあえず日本語表示は問題なさそうです。

Linux


Linux 上で Win32 用にクロスコンパイルしましたが、wxWidgets はクロスプラットフォーム対応のツールキットですので、Linux 上でそのまま、Linux ネイティブ用にコンパイルして実行することも(もちろん)できます。

$ g++ hello.cpp `wx-config --libs` `wx-config --cxxflags` -o hello
$ ./hello



[1] MinGW クロスコンパイル環境の設定
 

0 件のコメント: