投稿者 itouhiro
タグ [ Windows ゲーム ]

MinGW + SDL で Windowsソフト開発

Windows XP でゲームソフト開発環境を構築する方法をメモしておきます。

開発環境の構築

インストール

MinGW - Download から、Current バージョンの MinGW と MSYS をダウンロードする。 あと、MSYS Developer Tool Kit も(Perl とか入ってて) 便利なのでダウンロード。

(下記は 2005/5/06 現在のバージョン)

それぞれの exe を実行して、インストールする。

次に SDL 開発環境を導入。

SDL 1.2 の Development Libraries をダウンロード。

(下記は 2005/5/06 現在のバージョン)

上記のファイルを展開して出てきた SDL-1.2.8 というディレクトリを、C:\msys\1.0\ に local という名前で置きました。下記のディレクトリ構造になります。

  C:
  |-- msys
  |    |
  |    `-- 1.0
  |         |
  |         `-- local
  |               |-- bin
  |               |-- docs
  |               |-- include
  |               |     `-- SDL
  |               |-- lib
  |               |-- share
  |               `-- test

環境設定

環境変数を設定します。 HOME を設定しておきます。 Envvar setting

msys を実行します。 先ほどの HOME がカレントディレクトリになります。

MSYS execute

すでに MinGW の gcc には PATH が通ってるはずなので、

$ gcc --version

で上記のバージョン表記が出るはず。

動作テスト

SDL Setup Guide 1.1 にあるソース(下記) を試しにコンパイルしてみます。

/* -- Include the precompiled libraries -- */
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif

#include <SDL/SDL.h>

int main(int argc, char **argv) {
    printf("\nHello SDL User!\n");

    /* initialize SDL */
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        fprintf( stderr, "Video initialization failed: %s\n",
                 SDL_GetError( ) );
        SDL_Quit( );
    }

    SDL_Quit( );

    return 0;
}

コンパイルします。MSYS コンソールで下記のように直接入力してみましょう。

$ g++ -Wall test00.cpp -I/usr/local/include -L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mwindows

これでコンパイルできるはずだけど、なぜか SDL_audio.h:97: error: parse error before `[' token のエラーが出ます。

Google すると、メールアーカイブ [SDL] Re: parse error in SDL_audio.h using g++ and -mno-cygwin に解決法が載ってたので、c:\msys\1.0\local\include\SDL\SDL_audio.h を書き換えます。

--- /usr/local/include/SDL/SDL_audio.h.org      Sat May  7 14:28:36 2005
+++ /usr/local/include/SDL/SDL_audio.h  Sat May  7 14:29:40 2005
@@ -94,7 +94,7 @@
        int    len_cvt;                 /* Length of converted audio buffer */
        int    len_mult;                /* buffer must be len*len_mult big */
        double len_ratio;       /* Given len, final size is len*len_ratio */
-       void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format);
+       void ( *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format);
        int filter_index;               /* Current audio conversion function */
 } SDL_AudioCVT;

これでコンパイルが通り、実行できます。 a.exe を実行します。同じディレクトリに SDL.dll を C:\msys\1.0\local\bin からコピーして置いておく必要があるかもしれません。

execute a.exe

実行しても画面には何も出ませんが、a.exe のあるディレクトリに stdout.txt が作られ、その中に a.exe の出力した文字列が記載されています。

リンク

タグ [ Windows ゲーム ]
固定リンク http://ai11.net/2005/05/06/
ブックマーク はてなブクマ登録 Yahoo!ブクマ登録