Uli*_*ler 13 haskell ghc cabal
当运行Haskell程序导入几个这样的包时:
import Text.Feed.Import
import Network.HTTP
main = do
page <- simpleHTTP (getRequest "http://stackoverflow.com")
print $ page
Run Code Online (Sandbox Code Playgroud)
我得到一个像这样的错误(注意:这个问题打算解决一般问题,这个具体案例只是一个例子):
GHCi runtime linker: fatal error: I found a duplicate definition for symbol get_current_timezone_seconds
whilst processing object file
/usr/lib/ghc/time-1.4.0.1/HStime-1.4.0.1.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
Run Code Online (Sandbox Code Playgroud)
Uli*_*ler 23
为什么会出现此错误
此问题并非特定于单个程序包(例如,此处在三年前与Yesod相关),但是由您导入的不同库(例如HTTP和feed)链接到单个库的不同版本引起(此问题仅发生对于导出C风格符号的库.它们的符号名称不是唯一的.time是其中一个包.).
如错误消息中所示,导致此特定情况下的问题的库是time-1.4.0.1.
诊断确切的问题
首先,您需要确定库中存在哪些不同的版本.您可以通过使用检查软件包来执行此操作ghc-pkg describe <packagename>,或者只是查看cabal安装目录(通常~/.cabal/lib).
在撰写本文时,问题是由两者time-1.4.0.1和time-1.4.1正在安装引起的.通过使用ghc-pkg describe我发现feed(并且仅feed在我的情况下)链接到time-1.4.1大约100个链接到的库time-1.4.0.1.
如何解决
如上所述识别导致错误的库的库版本(如错误消息中所示),其中包含的包较少.您需要重建依赖它的所有包.就我而言,这是time-1.4.1.
然后,卸载包:
$ ghc-pkg unregister time-1.4.1 --force
unregistering time-1.4.1 would break the following packages: feed-0.3.9.2 (ignoring)
Run Code Online (Sandbox Code Playgroud)
请注意,feed程序包现在已损坏,需要重新构建并重新安装.但是重建后,它不会链接到time-1.4.1,但time-1.4.0.1(在我的具体情况).这种重新链接将解决重复的符号问题.
$ cabal install feed
Run Code Online (Sandbox Code Playgroud)
如果在此之后仍然发生错误,请重新检查所有依赖项,如上所述.您需要确保导入的任何库在显示时都会显示与其链接的库ghc-pkg describe <pkg>
更新:为了找出哪些软件包依赖于有问题的库,只需使用ghc-pkg unregister不带--force标志(感谢John J. Camilleri指出这一点!).请注意,如果没有包依赖于所述有问题的包,它将被删除.