简体   繁体   中英

Compile C++ Helloworld.cpp on VSCode and Mingw

I am trying to compile and run a simple HelloWorld program via VSCode on Windows 10 but it fails to compile, even when following their tutorial .

The only feedback I receive is:

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.

I don't even receive any further information what exactly has failed. How can this can be fixed? Quite curiously, the same 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

performs perfectly well when I invoke it in a separate 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:\Users\admin\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
}

Can you try returning zero in your program?

return 0;

Maybe the program is actually compiling and running but the non-zero return is interpreted as a failure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM