Skip to content

Instantly share code, notes, and snippets.

@Shivam60
Last active January 8, 2023 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shivam60/92feac1a9943d7bedfddaa46c3698848 to your computer and use it in GitHub Desktop.
Save Shivam60/92feac1a9943d7bedfddaa46c3698848 to your computer and use it in GitHub Desktop.
vscode tasks.json to Build & debug C++ programs using mingw64 g++
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-static-libstdc++",
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
@Shivam60
Copy link
Author

Shivam60 commented Jan 8, 2023

This is a standard task which gets generated the first time we try to debug a C++ program in vscode as we follow its instructions on setting up C++.

They key missing argument here is -static-libstdc++
I was getting error in debug console window of vscode terminal During startup program exited with code 0xc0000139. to the standard program that was mentioned in the official vscode instructions.

#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;
}

I tried to build the program from terminal using the command g++ hello-world.cpp -o hello.exe which it did successfully.

Then I commented out the vector declaration and program built and I was able to debug. This was a good hint and on further searching I found out that I was missing the libstdc++-6.dll or had two copies of it. This was the case for the terminal in which vscode was executing my program.

Googling the exact fix led me to libstdc++-6.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment