【问题标题】:C++ fatal error C1001: An internal error has occurred in the compilerC++ 致命错误 C1001:编译器发生内部错误
【发布时间】:2016-03-15 07:43:45
【问题描述】:

在发布模式下编译时出现以下错误。

1>d:\users\eyal\projects\code\yalla\core\src\runbox\win32\window.cpp : fatal error C1001: An internal error has occurred in the compiler.
1>         (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 249)
1>          To work around this problem, try simplifying or changing the program near the locations listed above.
1>         Please choose the Technical Support command on the Visual C++
1>          Help menu, or open the Technical Support help file for more information
1>           link!RaiseException()+0x48
1>           link!CxxThrowException()+0x65
1>           link!std::_Xout_of_range()+0x1f
1>           link!InvokeCompilerPass()+0x1b4e2
1>           link!InvokeCompilerPass()+0x22efe
1>           link!InvokeCompilerPass()+0x2332e
1>           link!InvokeCompilerPass()+0x232f9
1>           link!InvokeCompilerPass()+0x233cb
1>           link!InvokeCompilerPass()+0x22b04
1>           link!InvokeCompilerPass()+0x22d86
1>           link!DllGetC2Telemetry()+0x115837
1>
1>     1>
1>LINK : fatal error LNK1257: code generation failed

我正在使用 VS2015 Update 2 RC。

我不确定,但可能是优化器中的错误?

导致它的代码如下:

window.h

class Window {
public:
    Window();
    ~Window();
    void show();
    void hide();
private:
    class NativeControl;
    std::unique_ptr<NativeControl> _window;
};

window.cpp

class Window::NativeControl : public NativeWindow {
public:
    NativeControl() : NativeWindow() { }
};

Window::Window()
    : _window(std::make_unique<Window::NativeControl>()) {
}

Window::~Window() {
}

void Window::show() 
{
    _window->show(WindowShowMode::Show);
}

void Window::hide()
{
    _window->show(WindowShowMode::Hide);
}

NativeWindow 是任何操作系统的本机窗口。

这是使用 GCC 5.1 编译的工作代码: https://ideone.com/4YvjRK

只是为了做个笔记。

如果我要删除继承并用类似的东西替换它。

class Window::NativeControl {
public:
    void show(WindowShowMode showMode)
    {
    }
};

它会正常工作的!

下面是使用 GCC 5.1 编译的相同代码,没有继承: https://ideone.com/Mu0A42

导致这种行为的原因似乎是从 NativeWindow 派生了 NativeControl。

重现的步骤如下:

  1. 从 Window 类中删除 dtor 声明和定义。
  2. 尝试构建(而不是重建)。
  3. 编译器会抱怨并给你一堆错误。

1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory(1194): 错误 C2338: 无法删除不完整的类型 1> 1> 1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory(1195):警告 C4150:删除指向不完整类型“Yalla::Window::NativeControl”的指针;没有调用析构函数 1>
d:\Users\Eyal\Projects\Code\Yalla\core\src\runbox\include\window.h(13): 注意:参见 'Yalla::Window::NativeControl' 的声明 1>
window.cpp 1> 1>构建失败。

  1. 将 dtor 添加回 Window 类。
  2. 再次构建(不是重建)。
  3. 此时编译器应该报错以下错误“致命错误 C1001:编译器发生内部错误。”

有趣的是,重建似乎可以解决问题!

我想要实现的基本上是将 NativeWindow 的实际实现放在不同的文件中,主要是为了简单,而不是为了可重用性。

我想,不是在继承中这样做 这可能会混淆 unique_ptr 模板我还可以通过组合来做到这一点,并通过 getter 公开 NativeWindow 的实例,它可能 工作,但问题是是否有更好的方法来做到这一点?

我在很长一段时间没有接触它之后重新学习 C++,所以如果我正在做的一些事情没有意义,请告诉我! p>

更新:

C++ 标准说:

unique_ptr的模板参数T可能是不完整类型。

我在 Herb Sutter 的 blog 中找到了一篇关于它的帖子。

【问题讨论】:

  • 您能详细说明一下吗?就像我说的我正在重新学习 C++,已经有 10 年左右没有碰过这个了:D
  • NativeControlstd::unique_ptr&lt;NativeControl&gt; 中的不完整类型。指针不知道如何销毁不完整类型的指针。您应该将NativeControl 的完整声明放入window.h
  • ICE 总是编译器错误。 unique_ptr 的用法没有任何问题。
  • 显然这是一个编译器问题 (C1001)。转到 Microsoft Connect 并报告它。他们会要求提供代码。同时,您必须找到解决方法。 (我假设 Yalla 是一个命名空间)。关于NativeControl的不完整定义:应该可以。
  • 还有一件事:我的编译器版本是14.0.24720.00 Update 1,你有一个Release Candidate 版本,不是真正的版本。换句话说,你可能会更幸运Update 1

标签: c++ unique-ptr c1001


【解决方案1】:

类似的错误

(编译器文件 'f:\dd\vctools\compiler\utc\src\p2\main.c',第 255 行)

已修复更改 Properties-&gt;Linker-&gt;Optimization-&gt;Link Time Code Generation/LTCG:incremental/LTCG

Studio 2015 更新 3

【讨论】:

    【解决方案2】:

    我在构建一个简单的 C++ 命令行应用程序并使用 Microsoft Visual Studio Community 2019,版本 16.6.2 时遇到了类似的致命错误。

    project -&gt; properties -&gt; linker -&gt; optimizationrelease 配置的默认/LTCG:incremental 更改为/LTCG 解决了该问题。

    补充一点,这个错误是在最近的 VS2019 更新之一(不确定是哪一个)之后开始的。

    【讨论】:

      【解决方案3】:

      我解决了这个问题以链接 64 位的大型库。 Visual Studio 尝试使用默认(32 位链接)。

      Configuration Properties -&gt; Advanced -&gt; Preferred Build Tool Architecture -&gt; 64-bit (x64)

      【讨论】:

        【解决方案4】:

        编译器文件 p0io.c 相关的error C1001 主要是由于启用了支持区域设置的全球语言的“使用 Unicode UTF-8”。您可以查看有关具体原因的链接。你可以点击

        Time &amp;Language -&gt; Region-&gt; Additional date, time, &amp;regional settings-&gt; Region-&gt; Administrative-&gt;Change system locale

        并关闭 UTF-8。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-09-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-08-26
          • 2016-12-06
          相关资源
          最近更新 更多