相关疑难解决方法(0)

问题为GHC指定源目录

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

-i dirs

此标志将以冒号分隔的dirs列表附加到搜索路径.

所以,我尝试了以下调用:

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
Run Code Online (Sandbox Code Playgroud)

每次调用GHC都会给出错误:"<no location info>:找不到文件:Main.hs"

您可能已经猜到了,Main.hs位于名为"src"的工作目录的子目录中.万一重要,我使用的是Windows XP,我正在使用GHC 6.12.2.我假设有一些小问题,我只是缺少.

haskell ghc

9
推荐指数
1
解决办法
1808
查看次数

为什么ghci不使用相对路径?

如果我的项目结构如下:

project/
  src/
    Foo.hs
    Bar.hs
Run Code Online (Sandbox Code Playgroud)

使用文件Foo.hs:

module Foo where  

foo :: String
foo = "foo"
Run Code Online (Sandbox Code Playgroud)

和Bar.hs:

module Bar where

import Foo 

bar :: String
bar = foo ++ "bar"
Run Code Online (Sandbox Code Playgroud)

如果我的当前目录是src,并且我输入ghci并运行:l Bar.hs,我得到预期的输出:

[1 of 2] Compiling Foo              ( Foo.hs, interpreted )
[2 of 2] Compiling Bar              ( Bar.hs, interpreted )
Ok, modules loaded: Bar, Foo.
Run Code Online (Sandbox Code Playgroud)

但是,如果我移动到project目录(这是我宁愿留下并运行vim/ghci /等),并尝试:l src/Bar.hs,我得到:

src/Bar.hs:3:8:
    Could not find module ‘Foo’
    Use -v to see a list of the files …
Run Code Online (Sandbox Code Playgroud)

haskell ghci ghc-mod

3
推荐指数
1
解决办法
150
查看次数

标签 统计

haskell ×2

ghc ×1

ghc-mod ×1

ghci ×1