简体   繁体   English

在Visual Studio C ++中编译时出现错误2,代码退出MSB6006“ CL.exe”

[英]Error MSB6006 “CL.exe” exited with code 2 in compile in visual studio c++

I work on a c++ console project. 我在c ++控制台项目上工作。 this project has in msmpisdk platform. 该项目在msmpisdk平台中具有。 When I compiled in Visual Studio 2019 the error below occurred: 当我在Visual Studio 2019中编译时,发生以下错误:

"Severity Code Description Project File Line Suppression State...Error MSB6006 "CL.exe" exited with code 2....C:\\Program Files (x86)\\Microsoft VisualStudio\\2019\\Enterprise\\MSBuild\\Microsoft\\VC\\v160-\\Microsoft.CppCommon.targets 429." “严重性代码描述项目文件行抑制状态...错误MSB6006” CL.exe“退出,代码为2。...C:\\ Program Files(x86)\\ Microsoft VisualStudio \\ 2019 \\ Enterprise \\ MSBuild \\ Microsoft \\ VC \\ v160 -\\ Microsoft.CppCommon.targets429。”

I checked my code, it seems OK, also check ref lib of project, it seems OK. 我检查了我的代码,看来还可以,还检查了项目的ref lib,看来还可以。

I searched the web. 我在网上搜索。

  1. All functions return a value. 所有函数都返回一个值。
  2. All variables set a value before using it. 所有变量在使用前都会设置一个值。
  3. I restarted Visual Studio and my computer. 我重新启动了Visual Studio和我的计算机。
  4. I created new project and added the code, but the same error occurred. 我创建了新项目并添加了代码,但是发生了相同的错误。

but the same error occurred and my code doesn't compile. 但发生相同的错误,我的代码无法编译。

at last I found the problem. 最后我发现了问题。

  • one of my variable ,initialized in algorithm . 我的变量之一,已在算法中初始化。
  • but compiler can not detect variable initialized before and raise error. 但是编译器无法检测到之前初始化的变量并引发错误。
  • see below code to see how this error raised. 请参阅下面的代码,以查看此错误的产生方式。

 #include "iostream" class myclass1 { public: int _AMethod() { return 55; } }; int main() { myclass1* myVariable; int x = 0; if (x == 0) { myVariable = (myclass1*)malloc(sizeof(myclass1) * 5); //myVariable = init(); } if (x == 0) { myVariable->_AMethod(); } } 

now when compile this error occurred: Error MSB6006 "CL.exe" exited with code 2. 现在在编译时发生此错误:错误MSB6006“ CL.exe”退出,代码2。

  • all things in algorithm ok.. 算法中的所有内容都可以。
  • but compiler raise error .. 但是编译器会引发错误..

this error can solved easily .. with init in definition, like below : 通过定义init可以轻松解决此错误,如下所示:

 #include "iostream" class myclass1 { public: int _AMethod() { return 55; } }; int main() { myclass1* myVariable=(myclass1*)malloc(sizeof(myclass1) * 5); int x = 0; if (x == 0) { //myVariable = (myclass1*)malloc(sizeof(myclass1) * 5); //myVariable = init(); } if (x == 0) { myVariable->_AMethod(); } } 

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

相关问题 Visual Studio 2017 - 错误MSB6006:“CL.exe”退出代码2 - Visual studio 2017 - error MSB6006: “CL.exe” exited with code 2 错误MSB6006:“ CL.exe”退出,代码2 - error MSB6006: “CL.exe” exited with code 2 MSB6006 错误“CL.exe exited with code -1073741819”由代码错误引起 - MSB6006 error “CL.exe exited with code -1073741819” caused by errors in code 错误 MSB6006:添加模板函数或类后,“CL.exe”以代码 1 退出 - error MSB6006: "CL.exe" exited with code 1 after adding template function or class MSB6006:使用 openMP 时“CL.exe”退出,代码为 2 - MSB6006: “CL.exe” exited with code 2 when using openMP 链接Visual C ++项目(VS 2010)导致错误MSB6006:使用代码1073741515退出了“ link.exe” - Linking of Visual C++ project (VS 2010) results in the error MSB6006: “link.exe” exited with code 1073741515 错误MSB6006:“ fxc.exe”退出,代码为1 - error MSB6006: “fxc.exe” exited with code 1 错误MSB6006:Teamcity中的代码3退出了“ cmd.exe” - error MSB6006: “cmd.exe” exited with code 3 in Teamcity 错误MSB6006:“ midl.exe”退出,代码为-1073741515 - error MSB6006: “midl.exe” exited with code -1073741515 错误MSB6006:“ midl.exe”退出,代码为2026 - Error MSB6006: “midl.exe” exited with code 2026
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM