6

How would one go about creating an executable from a stack generated framework (stack new myprog simple)?

myprog.cabal shows myprog as executable that can be executed using stack exec myprog.

However: using ./myprog will not work. Not unless I call ghc --make src/Main.hs. This works obviously and nicely embeds the modules, but now the executable is called Main.

Is there a way to have stack compile myprog as a complete executable that can be called from anywhere assuming the environmental path is set?

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Madderote
  • 1,107
  • 10
  • 19

1 Answers1

12

As you may already be aware, stack build builds the executable, but then places it in a stack-specific path which can most easily be accessed using stack exec. However, there is another command: stack install, which then copies the executable to a convenient location. Normally the default location is in ~/.local/bin (I think), but you can use stack install --local-bin-path <PATH> to copy the executable to <PATH>. For instance, use stack install --local-bin-path . to place the executable in your current working directory, or use stack install --local-bin-path bin to place it in your ./bin/ directory. You can then run the executable using <PATH>/my-exe.

bradrn
  • 8,337
  • 2
  • 22
  • 51