【问题标题】:Error MSB6006 "CL.exe" exited with code 2 in compile in visual studio c++在 Visual Studio C++ 中编译时出现错误 MSB6006“CL.exe”并以代码 2 退出
【发布时间】:2020-01-15 03:09:14
【问题描述】:

我从事 C++ 控制台项目。这个项目在 msmpisdk 平台上。当我在 Visual Studio 2019 中编译时,出现以下错误:

“严重性代码描述项目文件行抑制状态...错误 MSB6006“CL.exe”退出,代码为 2....C:\Program Files (x86)\Microsoft VisualStudio\2019\Enterprise\MSBuild\Microsoft\ VC\v160-\Microsoft.CppCommon.targets 429。”

我检查了我的代码,似乎还可以,还检查了项目的 ref lib,似乎还可以。

我搜索了网络。

  1. 所有函数都返回一个值。
  2. 所有变量在使用前都设置了一个值。
  3. 我重新启动了 Visual Studio 和我的计算机。
  4. 我创建了新项目并添加了代码,但出现了同样的错误。

但发生了同样的错误,我的代码无法编译。

【问题讨论】:

标签: c++ visual-studio


【解决方案1】:

我终于找到了问题。

  • 我的一个变量,在算法中初始化。
  • 但编译器无法检测到之前初始化的变量并引发错误。
  • 请参阅下面的代码以了解此错误是如何引发的。

#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();
  }
}

现在编译时出现此错误: 错误 MSB6006 "CL.exe" 以代码 2 退出。

  • 算法一切正常..
  • 但编译器引发错误..

这个错误可以很容易地解决..在定义中使用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();
  }
}

【讨论】:

    猜你喜欢
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多