gpt4 book ai didi

haskell - 为 GHC 指定源目录的问题

转载 作者:行者123 更新时间:2023-12-04 03:46:10 25 4
gpt4 key购买 nike

这是一个令人尴尬的简单问题,但它的解决方案却让我望而却步。正如标题所示,我只想向 GHC 指定我所有源文件的位置。这应该很简单; GHC user guide :

-idirs

This flag appends a colon-separated list of dirs to the search path.



所以,我尝试了以下调用:
ghc -isrc/ -v -outputdir build/ --make -Wall Main.hs
ghc -isrc/: -v -outputdir build/ --make -Wall Main.hs
ghc -i:src/: -v -outputdir build/ --make -Wall Main.hs
ghc -i"src/" -v -outputdir build/ --make -Wall Main.hs
ghc -i"src/": -v -outputdir build/ --make -Wall Main.hs
ghc -i:"src/": -v -outputdir build/ --make -Wall Main.hs

每次调用 GHC 都会给出错误:“ : can't find file: Main.hs”

正如您可能已经猜到的那样,Main.hs 位于工作目录中名为“src”的子目录中。以防万一,我使用的是 Windows XP,并且使用的是 GHC 6.12.2。我假设我只是缺少一些小问题。

最佳答案

-i指定 GHC 将在何处搜索其他源文件,而不是您在命令行中指定的源文件。所以你的Main.hs还需要一个 src/前缀。例如。

$ ghc -isrc src/Main.hs --make 
[1 of 1] Compiling Main ( src/Main.hs, src/Main.o )
Linking src/Main ...

或者,您可以使用 cabal,并拥有 cabal init为您生成所有构建元数据。

关于haskell - 为 GHC 指定源目录的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5760280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com