5
votes

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 Files\Haskell Platform\8.2.1\msys

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:\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\snapshots\7eb65607\pkgdb --libdir=C:\sr\snapshots\7eb65607\lib --bindir=C:\sr\snapshots\7eb65607\bin --datadir=C:\sr\snapshots\7eb65607\share --libexecdir=C:\sr\snapshots\7eb65607\libexec --sysconfdir=C:\sr\snapshots\7eb65607\etc --docdir=C:\sr\snapshots\7eb65607\doc\haskell-gi-base-0.20.4 --htmldir=C:\sr\snapshots\7eb65607\doc\haskell-gi-base-0.20.4 --haddockdir=C:\sr\snapshots\7eb65607\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\8.2.1\msys\mingw64\include" "--extra-include-dirs=C:\Program Files\Haskell Platform\8.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\8.2.1\msys\mingw64\bin" "--extra-lib-dirs=C:\Program Files\Haskell Platform\8.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.

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 Files\Haskell Platform\8.2.1\msys\mingw64\include', 'C:\Users\Jacek\Downloads\glib-2.54.1','C:\Program Files\Haskell Platform\8.2.1\msys\mingw64\include\GLIB-2.0'] extra-lib-dirs: ['C:\Program Files\Haskell Platform\8.2.1\msys\mingw64\bin', 'C:\Program Files\Haskell Platform\8.2.1\msys\usr\bin']

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

2
You don't need to point to the glib sources. Haskell needs the compiled glib binary and the development includes. Usually, you get these by installing a dev version of glib, e.g. one you might find already ready-to-install on the web (easier), or one you can generate by compiling and installing the glib sources.chi
@chi How do I get the dev version of glib on MSYS2? That is why I went to ftp.gnome.org for sources. In the ideal world, I would need help from someone who tried the same on Windows.ruby_object
AFAIK, there's no devel package on MSYS2, the includes are shipped with the main package. Just list the available packages and install glib2. github.com/msys2/msys2/wiki/Using-packagesliberforce
@liberforce, thanks, I have found glib2 includes using pacman -Ql mingw-w64-x86_64-glib2. Now I suspect that Haskell can't find the existing directories because the path contains spaces.ruby_object
That's possible, look at msys2.org, at step 3 they say: Enter Installation Folder (ASCII, no accents, spaces nor symlinks, short path) .liberforce

2 Answers

2
votes

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:

  1. stack had previously been set up to use GHC 8.0.2 or GHC 8.2.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).

  3. 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.)

  4. 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:\msys64\mingw64\lib\pkgconfig
    XDG_DATA_DIRS=C:\msys64\mingw64\share
    

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

  5. I added C:\msys64\mingw64\bin 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.

  6. 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.

  7. 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:\msys64\mingw64\bin\ (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.)

  8. 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
    
  9. 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
    
  10. Then, the following worked as expected to build and run the example program:

    stack build
    stack exec gi-gtk-test
    
0
votes

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