【发布时间】:2013-12-22 02:32:36
【问题描述】:
我需要能够动态加载 Haskell 模块,并在动态加载模块的上下文中评估表达式。
Hint 做到了;问题是,至少在 Windows 上,它在 GHCi 下不起作用。
cygwin-bash> ghci HintTest.hs
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main>
Prelude Main> main
[... lots of "Loading package" messages snipped]
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
_debugLn
whilst processing object file
C:\PROGRAM FILES (X86)\HASKELL PLATFORM\2013.2.0.0\lib\ghc-prim-0.3.0.0\HSghc-prim-0.3.0.0.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry.
直接使用 GHC 模块时出现同样的错误,如GHC/As a library 所示。
作为编译程序,HintTest 运行良好。
对此有什么可以做的吗?
我不需要单独运行我的程序;总是使用 GHCi 就足够了。如果程序可以使用 GHCi 本身作为解释器而不是它自己的 GHC 副本,那也很好。也就是说,我希望能够做这样的事情:
do
context <- loadToGhci "MyModule.hs"
inContext context "MyModule.myFunction 2 5"
当我返回 REPL 时,MyModule 会神奇地加载到其中。 context 意味着某种带有 GHCi 状态的 monad。
更新 相同的代码适用于 Linux。也许这是 GHC 中特定于 Windows 的错误。可以解决吗?
更新 2 这是完整的日志
Prelude Main> main
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package bytestring-0.10.0.2 ... linking ... done.
Loading package Win32-2.3.0.0 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package old-locale-1.0.0.5 ... linking ... done.
Loading package time-1.4.0.1 ... linking ... done.
Loading package syb-0.4.0 ... linking ... done.
Loading package random-1.0.1.1 ... linking ... done.
Loading package filepath-1.3.0.1 ... linking ... done.
Loading package directory-1.2.0.1 ... linking ... done.
Loading package process-1.1.0.2 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package mtl-2.1.2 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package hpc-0.6.0.0 ... linking ... done.
Loading package hoopl-3.9.0.0 ... linking ... done.
Loading package haskell-src-1.0.1.5 ... linking ... done.
Loading package old-time-1.1.0.1 ... linking ... done.
Loading package Cabal-1.16.0 ... linking ... done.
Loading package binary-0.5.1.1 ... linking ... done.
Loading package bin-package-db-0.0.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package ghc-7.6.3 ... linking ... done.
Loading package extensible-exceptions-0.1.1.4 ... linking ... done.
Loading package MonadCatchIO-mtl-0.3.0.5 ... linking ... done.
Loading package ghc-mtl-1.0.1.2 ... linking ... done.
Loading package ghc-paths-0.1.0.9 ... linking ... done.
Loading package utf8-string-0.3.7 ... linking ... done.
Loading package hint-0.3.3.7 ... linking ... done.
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
_debugLn
whilst processing object file
C:\PROGRAM FILES (X86)\HASKELL PLATFORM\2013.2.0.0\lib\ghc-prim-0.3.0.0\HSghc-prim-0.3.0.0.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry.
【问题讨论】:
-
ghci 和 hint 都使用 ghc api。一次使用它两次很可能会导致在 Windows 上双重加载某些目标文件。如果是这种情况,除非您想更改 ghc api,否则您实际上无能为力。
-
@Carl 我刚刚在 Linux 上检查了相同的代码,它正在工作。也许这只是 Windows 特有的错误?
-
我不知道我是否正确理解了这个问题,但this 提到动态库在 Windows 上不完全支持,并且链接到与动态链接相关的大量错误,其中之一可能是您的问题。
-
@gereeter 我认为不涉及动态库。程序使用 GHCi 的加载器加载
.o文件。 -
@n.m.你能在你的帖子中包含“很多“加载包”输出吗?
标签: haskell ghci dynamic-loading