8
|-aseCswk2
  |-app
    |-Main.hs
  |-src
    |-Libs.hs
  |-test
    |-Spec.hs
  |-aseCswk2.cabal
  |-Setup.hs
  |-package.yaml
...

So i have a Haskell project that uses a Stack build system and is laid out as the example above. If i use $ stack test then my functions in my Libs.hs file are tested with the cases in my Spec.hs file. If i use $ stack build then my file builds successfully and i can use the functions inside $ stack ghci.

However, i want to create an executable of the my Main.hs file but don't know how this is possible. I have tried compiling it using $ ghc Main.hs inside the app directory but get an error saying 'Failed to load interface for Lib' even though i have included it as an import. I have also tried $stack build aseCswk2:exe:aseCswk2-exe but no .o files are created to run.

3
  • 2
    You can run the program with stack run. The files are constructed, in a hidden directory named .stack-world. Commented May 22, 2020 at 13:56
  • @WillemVanOnsem Thanks that's run my code Commented May 22, 2020 at 14:00
  • if you for example run stack build it prints at the last line the location of the executable. Commented May 22, 2020 at 15:42

1 Answer 1

6

Haskell-stack builds the executable in the hidden .stack-work directory. You can find out where the binaries are located that stack uses with:

$ stack path --local-install-root
/haskell/app/.stack-work/install/x86_64-linux/3fa5b3c3fbcd473981eef72c68d572129654cbb7c23af146b50d90e29c41b62f/8.6.5

In this directory, there is, if you build the application, a bin/ directory where the binary is located that has been built.

You can also run the application with:

$ stack run
Sign up to request clarification or add additional context in comments.

2 Comments

This command is not described in the introductory documentation of stack here: docs.haskellstack.org/en/stable/GUIDE Is there a way to change that? Or where to request the change?
@exchange stack path is documented in the advanced reference: docs.haskellstack.org/en/stable/path_command

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.