Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

msys2

gtk

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.

like image 524
ruby_object Avatar asked Oct 28 '22 23:10

ruby_object


1 Answers

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
    
like image 142
Mike Pilgrem Avatar answered Nov 15 '22 09:11

Mike Pilgrem