的Visual Studio 2017年 - 错误MSB6006: “CL.EXE” 与代码2
建设与Visual Studio 2017年一个项目,我遇到了这个错误退出:的Visual Studio 2017年 - 错误MSB6006: “CL.EXE” 与代码2
error MSB6006: "CL.exe" exited with code 2.
这里是我的代码:
int main()
{
const int WIDTH=800;
const int HEIGHT=600;
Bitmap bitmap(WIDTH, HEIGHT);
unique_ptr<int[]> histogram(new int[Mandelbrot::MAX_ITERATIONS + 1]{ 0 });
unique_ptr<int[]> fractal(new int[WIDTH*HEIGHT]{ 0 });
//int fractal[WIDTH*HEIGHT]{ 0 };
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
double xFractal = (x - WIDTH/2 - 200)*2.0/HEIGHT;
double yFractal = (y - HEIGHT/2)*2.0/HEIGHT;
int iterations = Mandelbrot::getIterations(xFractal, yFractal);
if (iterations != Mandelbrot::MAX_ITERATIONS) {
histogram[iterations]++;
}
fractal[y*WIDTH + x] = iterations;
uint8_t color = 256 * (double)iterations/Mandelbrot::MAX_ITERATIONS;
color = color*color*color;
bitmap.setPixels(x, y, color, color, color);
}
}
bitmap.write("Mandelbrot.bmp");
return 0;
}
的问题似乎是分形阵列的声明:
unique_ptr<int[]> fractal(new int[WIDTH*HEIGHT]{ 0 });
,如果我是(和评论其他线路与分形变量)的代码编译就好了,如果我将独特指针更改为普通的int数组,代码将编译,但是当我调试它时,会引发异常,表示出现堆栈溢出。
减小数组的大小解决了问题,所以看起来程序没有足够的内存空间来运行。我GOOGLE了很多,发现visual studio限制堆栈大小为1MB的deafult(我可能是错误的),但我无法找到如何在Visual Studio 2017手动增加它。有人可以帮助我吗?
编辑:这里是完整的输出:
1>------ Build started: Project: Fractal, Configuration: Debug Win32 ------
1>Main.cpp 1>INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX86\x86\CL.exe'
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>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(360,5):
error MSB6006: "CL.exe" exited with code 2. 1>Done building project
"Fractal.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
new int[N] { 0 }
并不意味着“填充数组用零”时,其实际上意味着骨料初始化由所述第一元素设置为0的数组,并对其余的值进行初始化(其余设置为0)。例如,如果您编写了{ 1 }
,则会将第一个元素设置为1
,但其他元素仍将为0
。
既然你已经依靠值初始化,您不妨在0
从{0}
删除,这也顺便让你的代码编译:
std::unique_ptr<int[]> fractal(new int[WIDTH*HEIGHT] {});
至于为什么你原来的代码没有按不会编译 - 这显然是Visual Studio 2017中的一个错误。请随时致电report it。
这里有一个最小的应用程序来重现问题:
int main()
{
auto test = new int[200000]{1};
delete[] test;
}
题外话:我很困惑,为什么你使用'的unique_ptr的''不是的std ::矢量'(或'的std ::数组“,因为你的大小可以编译时间常量) –
UnholySheep
你向我们展示的错误的行是最少的信息。请将* full *和* complete *错误消息复制粘贴到问题主体中。 –
使用完整的错误消息进行编辑。我仍然是一名初学者,我正在学习一门课程,老实说,我使用了独特的指针,因为他们在课程中使用过。我刚刚尝试使用向量,它的工作原理,而数组引发此异常:“在Fractal.exe 0x01393089未处理的异常:0xC00000FD:堆栈溢出(参数:0x00000000,0x00482000)。我现在很困惑,为什么这个矢量工作? –