Internal Compiler Error with C++ in Visual Studio

2019-05-13 00:56发布

问题:

I updated to Visual Studio 2015 Update 1 but now I am getting the following error when ever I compile a release configuration for 64 bit, everything works for 32 bit and/or debug builds.

fatal error C1001: An internal error has occurred in the compiler.
  (compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 246)
   To work around this problem, try simplifying or changing the program near the locations listed above.
  Please choose the Technical Support command on the Visual C++
   Help menu, or open the Technical Support help file for more information
    link!InvokeCompilerPass()+0x2d4bd
    link!DllGetC2Telemetry()+0xae663

The error occurs not for every of my projects but for some.

Simplifying the specified location is not really possible, the location where compiler is crashing is usually just a very simple one line function, also changing this code leads to the same error at a different location. As far as I can guess it has to do something with optimization and inlining. But changing optimization options didn't help either.

Can anyone point me to a direction how to locate the real problematic code or some compiler options to avoid this error?

I would like to not believe that that the update is broken.

回答1:

We encountered C1001 in one of our projects after upgrading to MSVC 2015 update 1.

Through trial-and-error, we've identified the ClCompile/AssemblerOutput property as the culprit in our case. Removing this property no longer caused C1001

Source: https://trac.osgeo.org/mapguide/ticket/2580

Update April 6th 2016: I tried building this same project with MSVC 2015 Update 2 without the ClCompile/AssemblerOutput property removed and I no longer get C1001 when building this project. I think Update 2 fixed it.



回答2:

Try setting up at project optimization to Disabled (/Od), it may resolve the issue.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box.
  2. Click the C/C++ folder.
  3. Click the Optimization property page.
  4. Modify the Optimization property.

Source: https://msdn.microsoft.com/en-us/library/aafb762y.aspx

I hope my answer supports your issue.



回答3:

Repro compiling a JSON lib in Release|x64. Config was set on maximize speed (/O2), but General was using "No Whole Program Optimization". Changing from "No Whole Program Optimization" to Use Link Time Code Generation (I believe the flag is /LTCG) build successfully.



回答4:

I also encountered this issue while we were converting our company's codebase from VC10 to VC14. In our case, the issue occurred when targeting x64 and SEH (/EHa) was enabled at the same time as Assembler Output was turned on. The error appeared to happen in our case when the stream insertion operator (i.e., std::cout::operator<<) was called in the compiled code.

In our case, dynamically linking the CRT instead of statically linking it (i.e., /MT instead of /MD) appears to work around the issue without disabling assembler output. This isn't the first issue that I've found with the statically-linked CRT (for example, it also caused missing cursors when resizing CPane windows in MFC).

This was reported to Microsoft (https://connect.microsoft.com/VisualStudio/feedback/details/2216490/compiler-crashes-at-string-stream-insertion-operator), but two and a half months later, it appears that they haven't even looked at it...

Edit: VS2015 Update 2 has, according to Micrsoft, fixed this issue. It tested as fixed on our codebase.