Using Mingw-w64 in VS Code

https://code.visualstudio.com/docs/cpp/config-mingw

 

1. install mingw, and the mingw bin folder to system path

 using cmd terminate to check it

g++ --version
gdb --version

2. install vs code & install extention  C++ in vs code (C/C++ IntelliSense, debugging, and code browsing)

3. run build task ctrl+shift+b, and it will promt to select a configuration.

 

 

For a project, makefile is the perfer solution.

1. easy c++ can be used to create a C++ project, in that, it will create a makefile. 

2. or cmakelist can be used to create a full project makefile. 

 

 

ctrl + shift + p :command palette

F8 go to the compilation error, shift +F8 go to next error

ctrl + , edit the setting

 

note:

Tab key does not work. 

Fix it by Ctrl + M

#directly c++

 task.json

{
   // See https://go.microsoft.com/fwlink/?LinkId=733558
   // for the documentation about the tasks.json format
   "version": "2.0.0",
   "tasks": [
      {
         "label": "build",
         "type": "cppbuild",
         "command": "C:/mingw/i686-8.1.0-release-win32-dwarf-rt_v6-rev0/mingw32/bin/g++.exe",
         "args": ["-g", "-static-libstdc++", "-static-libgcc", "${workspaceFolder}\\*.cpp", "-o", "${workspaceFolder}\\crc.exe"],
         "options": {
           "cwd": "${fileDirname}"
         },
         "problemMatcher": ["$gcc"],
         "group": {
           "kind": "build",
           "isDefault": true
         },
         "detail": "compiler: C:/mingw/i686-8.1.0-release-win32-dwarf-rt_v6-rev0/mingw32/bin/g++.exe"
      }
   ]
}

launch.json

{
   "version": "0.2.0",
   "configurations": [
     {
       "name": "g++.exe - Build and debug active file",
       "type": "cppdbg",
       "request": "launch",
       "program": "${workspaceFolder}\\crc.exe",
       "args": [],
       "stopAtEntry": false,
       "cwd": "${workspaceFolder}",
       "environment": [],
       "externalConsole": false,
       "MIMode": "gdb",
       "miDebuggerPath": "C:/mingw/i686-8.1.0-release-win32-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe",
       "setupCommands": [
         {
           "description": "Enable pretty-printing for gdb",
           "text": "-enable-pretty-printing",
           "ignoreFailures": true
         }
       ],
       "preLaunchTask": "build"
     }
   ]
 }

 

 

#easy c++ demo

mingw32-make is the make command.

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build C++ project",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "command": "mingw32-make",
        },
        {
            "label": "Build & run C++ project",
            "type": "shell",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "command": "mingw32-make",
            "args": [
                "run"
            ]
        }
    ]
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Debug (gdb)",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/main.exe",
            "preLaunchTask": "Build C++ project",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

posted on 2020-01-15 13:47  荷树栋  阅读(173)  评论(0)    收藏  举报

导航