Problem Specifying Source Directory to GHC

那年仲夏 提交于 2019-12-23 07:33:31

问题


This is an embarrassingly simple problem, but its solution yet eludes me. As the title indicates, I simply want to specify to GHC the location of all my source files. This should be simple; the GHC user guide:

-idirs

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

So, I tried the following invocations:

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

On every invocation GHC gave the error: "<no location info>: can't find file: Main.hs"

As you probably could have guessed, Main.hs is located in a subdirectory from the working directory called "src". Just in case it matters, I'm on Windows XP, and I'm using GHC 6.12.2. I'm assuming there is some small problem that I'm just missing.


回答1:


-i specifies where GHC will search for other source files, other than the ones you specify on the command line. So your Main.hs there will also need a src/ prefix. E.g.

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

Alternatively, you could use cabal, and have cabal init generate all the build metadata for you.



来源:https://stackoverflow.com/questions/5760280/problem-specifying-source-directory-to-ghc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!