如何在 Windows 上为 Haskell 开发设置 Gtk?

How do I set up Gtk on Windows for Haskell development?

到目前为止我已经安装了 https://www.haskell.org/platform/windows.html

的完整版本

最初,pacman 没有工作,所以我 运行 作为管理员 mingw64.exe 在

中找到
C:\Program Files\Haskell Platform.2.1\msys

我已经更新了 msys2 系统 运行ning pacman -Syu 并安装了所有 Gtk 库。我正在尝试使用堆栈编译 https://github.com/mmsbrggr/hsudoku。我已经克服了丢失的 dll 错误,现在我得到以下信息:

haskell-gi-base-0.20.4: configure

-- While building package haskell-gi-base-0.20.4 using: C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_1.24.2.0_ghc-8.0.2.exe --builddir=.stack-work\dist\ca59d0ab configure --with-ghc=C:\Users\Jacek\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc.EXE --with-ghc-pkg=C:\Users\Jacek\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --user --package-db=clear --package-db=global --package-db=C:\sr\snapshotseb65607\pkgdb --libdir=C:\sr\snapshotseb65607\lib --bindir=C:\sr\snapshotseb65607\bin --datadir=C:\sr\snapshotseb65607\share --libexecdir=C:\sr\snapshotseb65607\libexec --sysconfdir=C:\sr\snapshotseb65607\etc --docdir=C:\sr\snapshotseb65607\doc\haskell-gi-base-0.20.4 --htmldir=C:\sr\snapshotseb65607\doc\haskell-gi-base-0.20.4 --haddockdir=C:\sr\snapshotseb65607\doc\haskell-gi-base-0.20.4 --dependency=base=base-4.9.1.0 --dependency=bytestring=bytestring-0.10.8.1 --dependency=containers=containers-0.5.7.1 --dependency=text=text-1.2.2.2-9UQZjEJZQFSGMffj1Z5g00 "--extra-include-dirs=C:\Program Files\Haskell Platform.2.1\msys\mingw64\include" "--extra-include-dirs=C:\Program Files\Haskell Platform.2.1\msys\mingw64\include\GLIB-2.0" --extra-include-dirs=C:\Users\Jacek\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\include --extra-include-dirs=C:\Users\Jacek\Downloads\glib-2.54.1 "--extra-lib-dirs=C:\Program Files\Haskell Platform.2.1\msys\mingw64\bin" "--extra-lib-dirs=C:\Program Files\Haskell Platform.2.1\msys\usr\bin" --extra-lib-dirs=C:\Users\Jacek\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\bin --extra-lib-dirs=C:\Users\Jacek\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib Process exited with code: ExitFailure 1 Logs have been written to: C:\Users\Jacek\Documents\ExperimentingHaskell\hsudoku.stack-work\logs\haskell-gi-base-0.20.4.log

Configuring haskell-gi-base-0.20.4...
Cabal-simple_Z6RU0evB_1.24.2.0_ghc-8.0.2.exe: Missing dependencies on foreign
libraries:
* Missing C libraries: gobject-2.0, glib-2.0, intl
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.

我能够找到包含,但我担心某些编译器选项被引号括起来了。会不会有问题?

在Windows上使用Haskell和Gtk开发时如何正确添加开发文件?我如何告诉 Haskell 编译器在哪里可以找到包含?

extra-include-dirs: ['C:\Program Files\Haskell Platform.2.1\msys\mingw64\include', 'C:\Users\Jacek\Downloads\glib-2.54.1','C:\Program Files\Haskell Platform.2.1\msys\mingw64\include\GLIB-2.0'] extra-lib-dirs: ['C:\Program Files\Haskell Platform.2.1\msys\mingw64\bin', 'C:\Program Files\Haskell Platform.2.1\msys\usr\bin']

我的额外包含目录在编译器输出中似乎是乱码。

毕竟,我已经设法编译并启动了使用 Gtk 库编写的示例 Haskell 程序。

此要点是所采取步骤的记录。

https://gist.github.com/bigos/62defeec09a06f18ee38daf644af5340

我能够在 haskell-gi repository on 64-bit Windows (version 10.0.16299.125) using the Haskell Tool Stackstack,版本 1.6.3)中构建和 运行 示例 'Hello World' 程序,如下所示:

  1. stack 之前已设置为使用 GHC 8.0.2 或 GHC 8.2.2。

  2. 我按照 64 位 MSYS2 installer 的说明进行操作 Windows,接受默认值并更新(如说明中所述)。

  3. 打开 MSYS2 shell,然后我使用 pacman 安装包 mingw64/mingw-w64-x86_64-pkg-config mingw64/mingw-w64-x86_64-gobject-introspection mingw64/mingw-w64-x86_64-gtksourceview3 mingw64/mingw-w64-x86_64-webkitgtk3 .然后我返回到 Windows' 命令提示符。 (不过,不排除我安装了其他包的可能。)

  4. 我为我的帐户设置了以下 Windows 环境变量(通过在 Windows 10 中键入 'env' 找到“为您的帐户编辑环境变量”搜索栏):

    PKG_CONFIG_PATH=C:\msys64\mingw64\lib\pkgconfig
    XDG_DATA_DIRS=C:\msys64\mingw64\share
    

    第 3 步和第 4 步基于 page on the haskell-gi wiki

  5. 我在我帐户的 PATH 环境变量的开头附近添加了 C:\msys64\mingw64\bin。请参阅下面的第 7 步,了解在路径上首先找到的内容的重要性。

  6. 我使用 simple 模板创建了一个新的 Haskell 项目 gi-gtk-test,然后使用:

    移动到它的文件夹中
    stack new gi-gtk-test simple
    cd gi-gtk-test
    

    在撰写本文时,它使用 resolver: lts-10.1 (GHC 8.2.2) 创建了一个 stack.yaml 文件。 bug in GHC 8.2.2 表示它不适用于 gi-gtk,因此我将其更改为 resolver: lts-9.21 以恢复到 GHC 8.0.2。

  7. 这被证明是至关重要的一步:使用 stack exec where -- pkg-configstack exec where -- zlib1.dll 查看在 PATH 中首次遇到的版本stack 环境,我确保首先遇到的版本是 C:\msys64\mingw64\bin\ 中的版本(通过更改 PATH 上的文件夹顺序或将不需要的 zlib1.dll 重命名为 zlib1.dll.old). (我认为前者的其他版本导致有关 'missing C libraries' 的错误消息,而后者的其他版本导致带有关于 dll 的模糊消息的对话框。)

  8. 我在gi-gtk-test.cabal文件中添加了包gi-gtkhaskell-gi-base,如下:

    executable gi-gtk-test
      hs-source-dirs:      src
      main-is:             Main.hs
      default-language:    Haskell2010
      build-depends:       base >= 4.7 && < 5
                         , gi-gtk
                         , haskell-gi-base
    
  9. 我把Main.hs的内容改成了示例程序,即:

    {-# LANGUAGE OverloadedStrings, OverloadedLabels #-}
    
    module Main where
    
    import qualified GI.Gtk as Gtk  -- package gi-gtk
    import Data.GI.Base             -- package haskell-gi-base
    
    main :: IO ()
    main = do
      Gtk.init Nothing
      win <- new Gtk.Window [ #title := "Hi there" ]
      on win #destroy Gtk.mainQuit
      button <- new Gtk.Button [ #label := "Click me" ]
      on button #clicked (set button [ #sensitive := False,
                                       #label := "Thanks for clicking me" ])
      #add win button
      #showAll win
      Gtk.main
    
  10. 然后,下面的工作按预期构建和 运行 示例程序:

    stack build
    stack exec gi-gtk-test