【问题标题】:The type `Kaitai.Elf' already contains a definition for `Bits'`Kaitai.Elf' 类型已经包含了 `Bits' 的定义
【发布时间】:2018-07-08 10:36:06
【问题描述】:

我正在尝试从这个 stackexchange 答案编译代码:https://reverseengineering.stackexchange.com/a/16631/12521

添加系统导入和类定义后,我从http://formats.kaitai.io/elf/csharp.html 下载Elf.cs 并尝试编译它mcs -out:unpack.exe Elf.cs unpack.cs。但是,这会失败并出现以下错误:

Elf.cs(890,21): error CS0102: The type `Kaitai.Elf' already contains a definition for `Bits'
Elf.cs(97,21): (Location of the symbol related to previous error)
Elf.cs(895,23): error CS0102: The type `Kaitai.Elf' already contains a definition for `Endian'
Elf.cs(16,21): (Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings

运行 mcs Elf.cs 会产生相同的错误。不幸的是,我不是 C# 专家。我怎样才能让它正确编译。

【问题讨论】:

    标签: c# linux mono


    【解决方案1】:

    嗯,3年后,C#版本的ELF.ksy格式定义不能编译成C#了…… 唯一的选择是使用old one, from 2017。它仍然有错误,但更容易修复。

    【讨论】:

      【解决方案2】:

      要修复这些错误,您需要重命名第 890 和 895 行的属性,因为名称与文件中之前定义的枚举冲突。例如,您可以在末尾添加Value

      public Bits BitsValue { get { return _bits; } }
      
      //
      
      public Endian EndianValue { get { return _endian; } }
      

      但是,这个文件不能单独编译为:

      1. 这些类都继承自 KaitaiStruct 的东西,但这里不存在。
      2. KaitaiStream 对象被多次使用,也没有出现在此代码中。

      【讨论】:

        猜你喜欢
        • 2013-06-16
        • 1970-01-01
        • 1970-01-01
        • 2011-02-13
        • 1970-01-01
        • 2021-09-08
        • 2018-10-05
        • 2022-08-13
        • 1970-01-01
        相关资源
        最近更新 更多