Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell standalone executable without using 'stack exec'

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?

like image 269
Madderote Avatar asked Jun 13 '19 13:06

Madderote


1 Answers

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.

like image 131
bradrn Avatar answered Oct 25 '22 05:10

bradrn