ログ日記

作業ログと日記とメモ

やっとWindowsでHaskellからwxWidgetsが動くようになった

Cygwinは諦めてMsys上でコンパイルした。


一般的なことは
http://wiki.wxwidgets.org/Compiling_WxWidgets_With_MSYS-MinGW
ここに載っているが、別のやり方をする。


まずMinGWとMsysをインストールする。


wxMSW-2.8.11-Setup.exe をダウンロードして、Msysのlocalにインストールした。
Msysを立ち上げて

cd /local/wxWidgets-2.8.11/build/msw/
mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 SHARED=1 UNICODE=1

サンプルを実行してみる。
システムのプロパティからMinGWとMsysのbinにpathを通す。これは別に要らなかったかも。
WXWINをwxWidgetsのパスに設定して、WXCFGをgcc_dll/mswuに設定。これは実際にはwxWidgets-2.8.11/lib/gcc_dll/mswu/のこと。

cd ../..
cp lib/gcc_dll/wxmsw28u_gcc_custom.dll /bin/
cd samples/controls
mingw32-make -f makefile.gcc BUILD=release MONOLITHIC=1 SHARED=1 UNICODE=1
gcc_mswudll/controls

立ち上がれば成功。


wxconfigを取ってきてmsysのbinにでもPATHの通っている場所に入れておく。
http://sites.google.com/site/wxconfig/




cmd.exeを立ち上げてwx-config --libsの結果が返ってきたら成功。



Windows用の諸々の設定。
http://wewantarock.wordpress.com/2010/05/05/haskell-platform-2010-1-0-0-and-wxhaskell-on-windows/

cp /cygdrive/c/MinGW/libexec/gcc/mingw32/3.4.5/cc1plus.exe \
  /usr/local/Haskell-Platform/2010.1.0.0/mingw/libexec/gcc/mingw32/3.4.5/
cp /cygdrive/c/MinGW/lib/libstdc++.a \
  /usr/local/Haskell-Platform/2010.1.0.0/mingw/lib/
cp -a /cygdrive/c/MinGW/include/c++ \
  /usr/local/Haskell-Platform/2010.1.0.0/mingw/include/c++

Cygwinで色々やってたせいでPATHがいまいちだが気にせずに。



Haskell用のライブラリを入れる。

For all platforms, provided that wx-config is somewhere in the path and that the WXWIN environment variable points to the root of your wxWidgets installation installation is very straightforward.

On Windows platforms, you may also need to set WXCFG=gcc_dll/mswu. You can then install wxhaskell as follows (in a Windows cmd.exe shell, not an MSys shell):

WxHaskell/Building - HaskellWiki

cmd.exe 上で実行しないとダメみたい。
あとglobalで実行する。

cabal update
cabal install cabal-install --global
cabal install wx --global

# vistaではglobalでエラーが出たので一度user用に入れてからもう一度globalで入れたらうまくいった。
# が、コンパイル時にglobalとuserのバージョン不一致エラーが出たので片方を消した。正直よくわからない。



テスト。ここまで来ればCygwinからでもできる。

$ cat > test.hs
module Main where
import Graphics.UI.WX

main :: IO ()
main
  = start hello

hello :: IO ()
hello
  = do f    <- frame    [text := "日本語"]
       quit <- button f [text := "終了", on command := close f]
       set f [layout := margin 10 (column 5 [floatCentre (label "Hello")
                                            ,floatCentre (widget quit)
                                            ] )]
ghc --make -optl-mwindows test.hs
./test