繁体   English   中英

`cabal repl`导致GHC对使用C ++文件的简单项目感到恐慌

[英]`cabal repl` causes GHC panic on simple project with C++ files

我已将项目上传为zip文件,因此您可以尝试一下。 https://dl.dropboxusercontent.com/u/35032740/ShareX/2015/11/Buggy.zip

我想在限幅器库周围写一个包装器。 该代码使用cabal build编译良好,运行cabal runcabal repl产生此错误:

Preprocessing executable 'Buggy' for Buggy-0.1.0.0...
GHCi, version 7.10.2: http://www.haskell.org/ghc/  :? for help
GHC runtime linker: fatal error: I found a duplicate definition for symbol
   _ZNSt6vectorIN10ClipperLib8IntPointESaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_
whilst processing object file
   dist\build\Buggy\Buggy-tmp\wrapper.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.
ghc.exe: panic! (the 'impossible' happened)
  (GHC version 7.10.2 for x86_64-unknown-mingw32):
        loadObj "dist\\build\\Buggy\\Buggy-tmp\\wrapper.o": failed

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

作为参考,这是cabal文件

-- Initial Buggy.cabal generated by cabal init.  For further documentation,
--  see http://haskell.org/cabal/users-guide/

name:                Buggy
version:             0.1.0.0
-- synopsis:
-- description:
-- license:
license-file:        LICENSE
author:              Luka Horvat
maintainer:          lukahorvat9@gmail.com
-- copyright:
-- category:
build-type:          Simple
-- extra-source-files:
cabal-version:       >=1.10

executable Buggy
  main-is:             Main.hs
  c-sources:           clipper.cpp
                     , wrapper.cpp
  -- other-modules:
  -- other-extensions:
  build-depends:       base >=4.8 && <4.9
  -- hs-source-dirs:
  default-language:    Haskell2010
  extra-libraries:     stdc++

任何想法可能是什么原因在这里? 我正在运行Windows 10,64位。

我不知道Windows上目标文件格式的细节,所以我猜了一下。

可能clipper.owrapper.o都定义了一个名为_ZNSt6vectorIN10ClipperLib8IntPointESaIS1_EE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPS1_S3_EERKS1_符号。 (我在Linux上也看到了相同的内容。)这可能来自模板实例化( vector )。 弱符号指示系统链接器在遇到重复项时只选择符号的任何副本。

Windows上的GHCi不使用系统链接器,它有自己的运行时链接程序,可以在运行时将目标文件加载到自身。 因此,它通常与系统链接器不兼容。 可能运行时链接程序不能理解弱符号,至少在Windows上是这样( https://ghc.haskell.org/trac/ghc/ticket/3333 )。 从您得到的错误中,我们可以假设它将它们视为常规符号,并且不允许两个常规符号具有相同的名称。

作为解决方法,您可以使用-fno-weak构建C ++文件,如https://stackoverflow.com/a/26454930/190376中所述

如果这不起作用,另一种方法是将您的C ++文件构建到DLL中,您可以使用系统动态加载程序加载GHCi,从而避免了整个问题。 在Linux上,这看起来像

g++ wrapper.cpp clipper.cpp -shared -fPIC -o libclipper.so
ghci -L. -lclipper

虽然我认为Windows上的细节有所不同。

具体的错误不是我以前看到的,但是那些反斜杠说你在Windows上,而这看起来像GHC bug#3242 ,这已经引起了多年的痛苦。 好消息:两周前,这个事业终于被隔离了。 坏消息:该修复程序没有达到7.10.3的最后期限,尽管此时至少8.0.1里程碑似乎是安全的。

可能仍然值得将错误文本发布到该bug的线程; 我只是一个有根据的猜测,有人肯定会知道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM