我有similar setup like this SO question。 但是,我正在使用 stack 而不是直接使用 cabal :
stack.yaml
Test.cabal
src/FirstExe
src/SecondExe
堆栈文件很小
resolver: lts-8.17
packages:
- '.'
文件 Test.cabal 有2个可执行文件:
name: Test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8
executable FirstExe
hs-source-dirs: src
main-is: FirstExe.hs
build-depends: base >=4.8 && <4.10
executable SecondExe
hs-source-dirs: src
main-is: SecondExe.hs
build-depends: base >=4.8 && <4.10
src / FirstExe.hs 成功编译:
main :: IO ()
main = putStrLn "FirstExe compiles nicely"
src / SecondExe.hs 有错误:
main :: IO ()
main = "SecondExe gives compiler error" -- putStrLn is missing ...
(注意:此错误的目标是在堆栈构建 SecondExe 时看到。)
当我做stack ide targets
时,我得到了
Test:exe:FirstExe
Test:exe:SecondExe
现在我想编译仅第一个目标 FirstExe 而不编译第二个目标而不更改 Test.cabal 文件。实际上,我将在2个可执行文件之间切换。
根据Haskell Tool Stack documentation它应该 可能
我尝试了两种可能性:
stack build :FirstExe
stack build Test:exe:FirstExe
在这两种情况下,它也会编译第二个可执行文件!
Test-0.1.0.0: configure (exe)
Configuring Test-0.1.0.0...
Test-0.1.0.0: build (exe)
Preprocessing executable 'FirstExe' for Test-0.1.0.0...
Preprocessing executable 'SecondExe' for Test-0.1.0.0...
[1 of 1] Compiling Main ( src/SecondExe.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0/build/SecondExe/SecondExe-tmp/Main.o )
/home/roland/Projekte/HaskellTutorials/Test/src/SecondExe.hs:2:8: error:
* Couldn't match expected type `IO ()' with actual type `[Char]'
* In the expression: "SecondExe gives compiler error"
In an equation for `main': main = "SecondExe gives compiler error"
-- While building package Test-0.1.0.0 using:
/home/roland/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0 build exe:FirstExe exe:SecondExe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
我做错了什么?