A minimal reproduction can be found here:
https://github.com/IvanMalison/stack-gtk2hs-bug
Everything works as expected when I use normal stack commands, but when I run the failing command:
stack ghc -- --make main.hs
I get the following error:
main.hs:3:1: error:
Ambiguous interface for ‘Graphics.UI.Gtk’:
it was found in multiple packages: gtk-0.14.6 gtk3-0.14.6
main.hs:4:1: error:
Ambiguous interface for ‘Graphics.UI.Gtk.Abstract.Widget’:
it was found in multiple packages: gtk-0.14.6 gtk3-0.14.6
main.hs:5:1: error:
Ambiguous interface for ‘Graphics.UI.Gtk.Layout.Table’:
it was found in multiple packages: gtk-0.14.6 gtk3-0.14.6
The output of stack exec ghc-pkg -- --no-user-package-db list is https://gist.github.com/f19f900988f49e4d03cd61f1cab48baa . This output makes me expect that the reason that this is happening is that some other stack install required gtk (not gtk3 which is what is specified as a dependency in this package) and somehow this package is visible from the stack ghc command for some reason.
Am I misunderstanding the stack ghc command? Shouldn't this essentially do the same thing as stack build?
There's no builtin way to do this with stack currently. However, it is possible to get
stack ghcito do this. The most straightforward way to do it is to make a cabal package which has the executable target. However, if you really want to just use straight ghc, there is a way. Copy-pasting from my comment here:stack ghcworks a bit differently thanstack ghci. It's essentially a synonym forstack exec -- ghc, which will run the right compiler with the right databases, but won't set up anything related to your local packages like include directories etc. Note thatstack ghcitakes TARGET arguments whereasstack ghcdoes not. Retrospectively, this is a bit inconsistent, butstack ghccame beforestack ghci.It does make sense to have the ability to do something like this, though not sure how to best achieve that. Some potential options:
--no-interactiveargument onstack ghci. Would be a bit obtuse. Weird to run aghcicommand when, though it would be using thestack ghcilogic.Add
--target TARGEToption tostack ghc, to tell it to use the environment of a particular local package target.Here's a workaround for now. Put the following in
~/.local/bin/stack-run-ghc.shand make it user executable:This takes the arguments, removes
--interactive, and calls ghc. With this, I can build stack using ghc via the following:stack ghci --with-ghc stack-run-ghc.sh --ghci-options src/main/Main.hs