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

So far I have installed full version from https://www.haskell.org/platform/windows.html

Initially, pacman did not work so I did run as an administrator mingw64.exe found in

C:Program FilesHaskell Platform8.2.1msys

I have updated the msys2 sytem running pacman -Syu and installed all Gtk libraries. I am trying to compile https://github.com/mmsbrggr/hsudoku using stack. I have gone past the missing dll errors and now I get the following:

haskell-gi-base-0.20.4: configure

-- While building package haskell-gi-base-0.20.4 using: C:srsetup-exe-cachex86_64-windowsCabal-simple_Z6RU0evB_1.24.2.0_ghc-8.0.2.exe --builddir=.stack-workdistca59d0ab configure --with-ghc=C:UsersJacekAppDataLocalProgramsstackx86_64-windowsghc-8.0.2binghc.EXE --with-ghc-pkg=C:UsersJacekAppDataLocalProgramsstackx86_64-windowsghc-8.0.2binghc-pkg.EXE --user --package-db=clear --package-db=global --package-db=C:srsnapshots7eb65607pkgdb --libdir=C:srsnapshots7eb65607lib --bindir=C:srsnapshots7eb65607bin --datadir=C:srsnapshots7eb65607share --libexecdir=C:srsnapshots7eb65607libexec --sysconfdir=C:srsnapshots7eb65607etc --docdir=C:srsnapshots7eb65607dochaskell-gi-base-0.20.4 --htmldir=C:srsnapshots7eb65607dochaskell-gi-base-0.20.4 --haddockdir=C:srsnapshots7eb65607dochaskell-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 FilesHaskell Platform8.2.1msysmingw64include" "--extra-include-dirs=C:Program FilesHaskell Platform8.2.1msysmingw64includeGLIB-2.0" --extra-include-dirs=C:UsersJacekAppDataLocalProgramsstackx86_64-windowsmsys2-20150512mingw64include --extra-include-dirs=C:UsersJacekDownloadsglib-2.54.1 "--extra-lib-dirs=C:Program FilesHaskell Platform8.2.1msysmingw64bin" "--extra-lib-dirs=C:Program FilesHaskell Platform8.2.1msysusrbin" --extra-lib-dirs=C:UsersJacekAppDataLocalProgramsstackx86_64-windowsmsys2-20150512mingw64bin --extra-lib-dirs=C:UsersJacekAppDataLocalProgramsstackx86_64-windowsmsys2-20150512mingw64lib Process exited with code: ExitFailure 1 Logs have been written to: C:UsersJacekDocumentsExperimentingHaskellhsudoku.stack-worklogshaskell-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.

I am able to find includes, but I am concerned that some compiler options are wrapped in quotes. Could it be a problem?

How do I correctly add development files when I develop with Haskell and Gtk on Windows? How do I tell the Haskell compiler where it can find the includes?

extra-include-dirs: ['C:Program FilesHaskell Platform8.2.1msysmingw64include', 'C:UsersJacekDownloadsglib-2.54.1','C:Program FilesHaskell Platform8.2.1msysmingw64includeGLIB-2.0'] extra-lib-dirs: ['C:Program FilesHaskell Platform8.2.1msysmingw64bin', 'C:Program FilesHaskell Platform8.2.1msysusrbin']

My extra-include dirs seem to be garbled in the compiler output.


I was able to build and run the example 'Hello World' program at the haskell-gi repository on 64-bit Windows (version 10.0.16299.125) using the Haskell Tool Stack ( stack , version 1.6.3) as follows:

  • stack had previously been set up to use GHC 8.0.2 or GHC 8.2.2.

  • I followed the instructions for the MSYS2 installer for 64-bit Windows, accepting the defaults and updating (as set out in the instructions).

  • Opening a MSYS2 shell, I then used pacman to install packages 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 . I then returned to Windows' Command Prompt. (However, I can't rule out that I may have installed other packages.)

  • I set up the following Windows environment variables for my account (finding `Edit environment variables for your account' by typing 'env' into the Windows 10 search bar):

    PKG_CONFIG_PATH=C:msys64mingw64libpkgconfig
    XDG_DATA_DIRS=C:msys64mingw64share
    

    Steps 3 and 4 were based on a page on the haskell-gi wiki.

  • I added C:msys64mingw64bin near the start of the PATH environment variable for my account. See step 7 below about the importance of what is found first on the path.

  • I created a new Haskell project gi-gtk-test with a simple template and then moved into its folder using:

    stack new gi-gtk-test simple
    cd gi-gtk-test
    

    At the time of writing, that created a stack.yaml file with resolver: lts-10.1 (GHC 8.2.2). A bug in GHC 8.2.2 means that it does not work with gi-gtk , so I changed that to resolver: lts-9.21 to revert to GHC 8.0.2.

  • This proved to be a vital step: Using stack exec where -- pkg-config and stack exec where -- zlib1.dll to see what versions were first encountered on the PATH that is set up in the stack environment, I made sure that the versions first encountered were those in C:msys64mingw64bin (by changing the order of folders on my PATH or renaming unwanted zlib1.dll as zlib1.dll.old ). (I think that other versions of the former resulted in error messages about 'missing C libraries' and other versions of the latter resulted in dialog boxes with obscure messages about dlls.)

  • I added the packages gi-gtk and haskell-gi-base to the gi-gtk-test.cabal file, as follows:

    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
    
  • I changed the contents of Main.hs to be the example program, namely:

    {-# 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
    
  • Then, the following worked as expected to build and run the example program:

    stack build
    stack exec gi-gtk-test
    

  • After all, I have managed to compile and launch example Haskell program written using Gtk library.

    This gist is the record of the steps taken.

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

    链接地址: http://www.djcxy.com/p/75482.html

    上一篇: 如何将Ubuntu / Debian Linux中的init.d脚本翻译成Solaris?

    下一篇: 如何在Windows上为Haskell开发设置Gtk?