用VS代码运行C/C++代码总是抛出“exited with code=1 in 0.123 seconds”

xriantvc  于 12个月前  发布在  C/C++
关注(0)|答案(1)|浏览(226)

我试图设置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.

谢谢!

2uluyalo

2uluyalo1#

这不管用但我解决了这个问题:基本上,我使用windows finder找到了gcc.exe的所有示例,并删除了程序文件中存放它们的文件夹。然后我从环境变量中删除了它们的路径。最后,我通过cygwin重新安装了gcc-core和gcc-g++,并且成功了

相关问题