0

Packages that are distributed without using stack or cabal usually have a set of implied dependencies. This sometimes mean that running ghc directly on said packages will not work without installing packages into ghcs global package database.

I would like to use stack ghc as a replacement for ghc to this end I have defined the following in my shells init file:

export PATH="`stack path --compiler-bin`:$PATH"

Now the command ghc will use stack's ghc - it does not however do the same as stack ghc. For one, it does not load the "snapshot" and "global-project" package database as can be seen with the following commands:

$ ghc -v
Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version 7.10.3
Using binary package database: ~/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/package.conf.d/package.cache
...
$ stack ghc -- -v
Glasgow Haskell Compiler, Version 8.0.1, stage 2 booted by GHC version 7.10.3
Using binary package database: ~/.stack/programs/x86_64-linux/ghc-nopie-8.0.1/lib/ghc-8.0.1/package.conf.d/package.cache
Using binary package database: ~/.stack/snapshots/x86_64-linux-nopie/lts-7.9/8.0.1/pkgdb/package.cache
Using binary package database: ~/.stack/global-project/.stack-work/install/x86_64-linux-nopie/lts-7.9/8.0.1/pkgdb/package.cache
...

Does anyone have guidance on how to achieve using stack ghc as a replacement for ghc.

The use-case I currently have is that I have been given a make-file that refers to ghc - but I do not have this command on my machine.

fredefox
  • 681
  • 3
  • 11

1 Answers1

1

If you execute the makefile within stack exec, it will set the GHC_PACKAGE_PATH environment variable. It will also extend PATH appropriately.

Alternatively, to have this set in your shell you could do

export GHC_PACKAGE_PATH=`stack path --ghc-package-path`
mgsloan
  • 3,245
  • 21
  • 20