[英]Haskell standalone executable without using 'stack exec'
How would one go about creating an executable from a stack
generated framework ( stack new myprog simple
)?如何从
stack
生成的框架( stack new myprog simple
)创建可执行文件?
myprog.cabal
shows myprog
as executable that can be executed using stack exec myprog
. myprog.cabal
myprog
显示为可执行文件,可以使用stack exec myprog
执行。
However: using ./myprog
will not work.但是:使用
./myprog
将不起作用。 Not unless I call ghc --make src/Main.hs
.除非我调用
ghc --make src/Main.hs
。 This works obviously and nicely embeds the modules, but now the executable is called Main
.这很明显并且很好地嵌入了模块,但现在可执行文件被称为
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?有没有办法让
stack
编译myprog
作为一个完整的可执行文件,假设设置了环境路径,它可以从任何地方调用?
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
.您可能已经知道,
stack build
会构建可执行文件,然后将其放置在特定于stack
路径中,使用stack exec
最容易访问该路径。 However, there is another command: stack install
, which then copies the executable to a convenient location.但是,还有另一个命令:
stack install
,然后将可执行文件复制到一个方便的位置。 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>
.通常默认位置在
~/.local/bin
(我认为),但您可以使用stack install --local-bin-path <PATH>
将可执行文件复制到<PATH>
。 For instance, use stack install --local-bin-path .
例如,使用
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.将可执行文件放置在您当前的工作目录中,或使用
stack install --local-bin-path bin
将其放置在您的./bin/
目录中。 You can then run the executable using <PATH>/my-exe
.然后,您可以使用
<PATH>/my-exe
运行可执行文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.