在OS X上使用wxHaskell

4

我希望在我的苹果电脑上(MacBook Pro,Snow Leopard系统)使用wxHaskell库进行开发。我已经成功地安装了这个库,并且下面的脚本:

module Main where
import Graphics.UI.WX

main :: IO ()
main = start hello

hello :: IO ()
hello
  = do f    <- frame    [text := "Hello!"]
       quit <- button f [text := "Quit", on command := close f]
       set f [layout := widget quit]

执行结果确实会显示一个指定的单按钮窗口。但是,当我点击按钮时,什么事情也没有发生——甚至没有得到按钮变蓝以指示已经按下的视觉响应(哈哈,不是双关语)。

我听说,在wxHaskell二进制文件上运行一个名为“macosx-app”的软件包,可以使它们运行,但我找不到这个软件包。 在我的计算机或(据我所知)在WX或wxHaskell散发中都找不到。

有人知道我需要做什么才能让这个工作吗?


你按照这个链接的指示在Mac上安装了吗?http://haskell.org/haskellwiki/WxHaskell/MacOS_X - Don Stewart
1
没错,一切都好,除了命令"/usr/local/wxhaskell/bin/macosx-app -v helloworld" 这个命令丢失了... - Bill
2个回答

2

源代码发布包括一个名为macosx-app-template的文件,位于bin目录中。该文件由configure脚本的以下部分用于创建macosx-app

cat > config/macosx-app-temp << EOF
#!/bin/sh
rezcomp="$wxinstallrezcomp"
rezfile="$wxinstallrezfile"

EOF
cat config/macosx-app-temp bin/macosx-app-template > config/macosx-app
rm -f config/macosx-app-temp
chmod a+x config/macosx-app

如果您已经安装了wxHaskell并且没有使用configure脚本,那么您可以复制这些步骤,即将macosx-app-template复制到macosx-app,使其可执行,并在顶部添加以下行:
#!/bin/sh

libdir=""

wxrezcomp="`wx-config --rezflags`"
wxrezfile=""
if test "$wxrezcomp"; then
  for word in $wxrezcomp; do
    temp="`echo $word | grep '[^_]*_mac-[^r]*r'`"
    if test "$temp"; then
      wxrezfile="$temp"
    fi
  done
fi

if test "$wxrezfile"; then
  wxrezdir="`echo $wxrezfile | sed -e 's|\(.*\)/libwx_mac.*|\1|'`"
  wxinstallrezcomp="`echo \"${wxrezcomp}\" | sed -e \"s|${wxrezdir}|${libdir}|g\"`"
  wxinstallrezfile="`echo \"${wxrezfile}\" | sed -e \"s|${wxrezdir}|${libdir}|g\"`"
fi

rezcomp="$wxinstallrezcomp"
rezfile="$wxinstallrezfile"

请注意,您需要更改libdir = ""以指定安装wxHaskell库文件的目录,如果wx-config不在您的路径中,则还需要更改该行。

现在看来,wxHaskell(0.12.1.6)通过Cabal进行分发;Cabal从Hackage下载的tar.gz文件缺少bin/子目录条目,更不用说macosx-app-template了。我们这些Mac迷还有希望吗? - corwin.amber

0

我使用cabal安装了wxhaskell,并阅读其他说明后,按如下步骤进行操作,以使macosx-app正常工作:

  1. 我从http://haskell.org/haskellwiki/WxHaskell/Download下载了wxhaskell源代码

  2. 我解压缩下载的文件:

    wxhaskell-src-XXX.zip

    其中XXX是版本号

  3. 我在解压缩的目录中运行configure。这将从模板创建文件config/macosx-app

    .configure

  4. 我使用sudo将该文件复制到bin目录/usr/local/bin中

    sudo cp config/macosx-app /usr/local/bin

  5. 我删除包含源文件的目录

对我有效!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接