【问题标题】:Running C/C++ code with VS code always throw "exited with code=1 in 0.123 seconds"使用 VS 代码运行 C/C++ 代码总是抛出“exited with code=1 in 0.123 seconds”
【发布时间】:2021-10-07 00:02:02
【问题描述】:

我正在尝试将 VScode 设置为能够使用 Code Runner 包为 C 和 C++ 代码提供“Code Runner”包,但它总是会出错:

[Running] cd "d:\Desktop\Programming\For_fun\tester\" && g++ practice.cpp -o practice && "d:\Desktop\Programming\For_fun\tester\"practice

[Done] exited with code=1 in 0.123 seconds

我发现使用 wsl 和 ubuntu 编译和运行会起作用,但常规命令提示符不会。我认为这是问题所在的一个重要指标,但我不知道如何解决它甚至开始谷歌搜索。

我使用的是 Windows 10

这是我的代码:

#include <vector>
#include <iostream>
#include <string>
using namespace std;

int main() {
  cout << "Hello World!\n";
  return 0;
}

这些是我试图确认我是否安装了相关软件包的结果:

PS D:\Desktop\Programming\For_fun\tester> c++ --version
c++.exe (MinGW.org GCC Build-20200227-1) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

PS D:\Desktop\Programming\For_fun\tester> gcc --version
gcc.exe (Rev5, Built by MSYS2 project) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.

PS D:\Desktop\Programming\For_fun\tester> g++ --version
g++.exe (MinGW.org GCC Build-20200227-1) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

谢谢!

【问题讨论】:

  • 尝试在shell(命令提示符)中完全编译和运行。从您的日志中可以清楚地看到要编译的命令:g++ practice.cpp -o practice。它是否显示任何错误?
  • 它不起作用。但我解决了这个问题:基本上,我使用 windows finder 来查找 gcc.exe 的所有实例,并删除了我的程序文件中包含它们的文件夹。然后我从我的环境变量中删除了它们的路径。最后,我通过 cygwin 彻底重新安装了 gcc-core 和 gcc-g++,并且成功了。
  • 所以这是一个错误的安装。您可能想删除您的问题或自己写一个答案,以便以后标记。请不要一直打开。
  • 谢谢!我将其复制并粘贴为答案

标签: c++ c windows visual-studio-code


【解决方案1】:

它不起作用。但我解决了这个问题:基本上,我使用 windows finder 来查找 gcc.exe 的所有实例,并删除了我的程序文件中包含它们的文件夹。然后我从我的环境变量中删除了它们的路径。最后,我通过 cygwin 重新安装了 gcc-core 和 gcc-g++,它工作了

【讨论】:

    猜你喜欢
    • 2012-09-28
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多