簡體   English   中英

在 VSCode 和 Mingw 上編譯 C++ Helloworld.cpp

[英]Compile C++ Helloworld.cpp on VSCode and Mingw

我正在嘗試通過 Windows 10 上的 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\mingw32\bin\g++.exe' -g c:\Users\admin\programming\helloworld.cpp -o c:\Users\admin\programming\helloworld.exe" terminated with exit code: 1.

我什至沒有收到任何進一步的信息,究竟是什么失敗了。 如何解決這個問題? 很奇怪,同樣的命令

& '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

當我在單獨的 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\tasks.json

{
    "version": "2.0.0",
    "tasks": [
      {
        "type": "shell",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
        "args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
        "options": {
          "cwd": "${workspaceFolder}"
        },
        "problemMatcher": ["$gcc"],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }

C:\用戶\管理員\programming.vscode\c_cpp_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;

也許程序實際上正在編譯和運行,但非零返回被解釋為失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM