C++ 编译C++;VSCode和Mingw上的Helloworld.cpp
我试图在Windows10上通过VSCode编译并运行一个简单的HelloWorld程序,但它无法编译,即使在遵循他们的命令时也是如此 我收到的唯一反馈是:C++ 编译C++;VSCode和Mingw上的Helloworld.cpp,c++,visual-studio-code,mingw,C++,Visual Studio Code,Mingw,我试图在Windows10上通过VSCode编译并运行一个简单的HelloWorld程序,但它无法编译,即使在遵循他们的命令时也是如此 我收到的唯一反馈是: The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\min
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g c:\Users\admin\programming\helloworld.cpp -o c:\Users\admin\programming\helloworld.exe" terminated with exit code: 1.
我甚至没有收到任何进一步的信息,究竟是什么失败了。如何解决这个问题?奇怪的是,同样的命令
和'C:\ProgramFiles(x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt\uv6-rev0\mingw32\bin\g++.exe'-gc:\Users\admin\programming\helloworld.cpp-o C:\Users\admin\programming\helloworld.exe
当我在单独的powershell中调用它时,执行得非常好
C:\Users\admin\programming\Helloworld.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
C:\Users\admin\programming.vscode\C\u cpp\u properties.json
{
"configurations": [
{
"name": "GCC",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"cppStandard": "c++17"
}
],
"version": 4
}
你能试着在你的程序中返回零吗
return 0;
可能程序实际上正在编译和运行,但非零返回被解释为失败。只是好奇,您是否尝试过使用msbuild编译?@user3389943否,但它尚未安装。我刚刚补充说,编译器命令在单独的powershell中工作得非常好,所以我相信这不是编译器的错。你有下面教程的链接吗?你的mingw与C++17兼容吗?可能我唯一看到的是在cpp属性中指定的C++17,这可能是问题所在,也可能不是问题所在。@user3389943:无效
main
默认情况下,如果控件到达}
,则返回0
。我没有对此进行否决,但没有迹象表明代码曾经执行过。没有生成可执行文件。
return 0;