Skip to content

VSCode C/CPP Environment

1. Install MinGWFor details, please refer to [C++ environment settings]

2. Configure VSCodeCreate a.vscodefolder under the source code folder, which containsc_cpp_properties.json,launch.json,tasks.json. For the specific meaning of each file, please refer to [VScode tasks.json and launch.json settings], [VSCode predefined variables]### (1).c_cpp_properties.jsonNeed to change MinGW path to actual path```

{ "configurations": [ { "name": "RHEL7.2->Linux", "includePath": [ "\({workspaceFolder}/**", "/opt/scadacom/current/**" ], "forcedInclude": [], "defines": [], "compilerPath": "/usr/bin/g++", "cStandard": "c11", "cppStandard": "c++11", "intelliSenseMode": "linux-gcc-x64", "compilerArgs": [ //Release "-std=c++11", "-w", "-O2", "-pipe", "-m64", "-D_REENTRANT", "-DQT_SHARED", "-DQT_NO_DEBUG_OUTPUT", "-DQT_NO_DEBUG", "-DQT_GUI_LIB", "-DQT_NETWORK_LIB", "-DQT_CORE_LIB", "-DQT_SHARED" ] }, { "name": "RHEL7.2-WindowsLocal", "includePath": [ "\)/", "~/Documents/Codes/include/RHEL7.2S5.8.10/", "C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/x86_64-w64-mingw32/include" ], "forcedInclude": [], "defines": [], "compilerPath": "C:/ProgramData/chocolatey/bin/g++.exe", "cStandard": "c11", "cppStandard": "c++11", "intelliSenseMode": "linux-gcc-x64", "compilerArgs": [ //Release "-std=c++11", "-w", "-O2", "-pipe", "-m64", "-D_REENTRANT", "-DQT_SHARED", "-DQT_NO_DEBUG_OUTPUT", "-DQT_NO_DEBUG", "-DQT_GUI_LIB", "-DQT_NETWORK_LIB", "-DQT_CORE_LIB", "-DQT_SHARED" ], "mergeConfigurations": false, "browse": { "path": [ "${workspaceFolder}/", "~/Documents/Codes/include/RHEL7.2S5.8.10/" ], "limitSymbolsToIncludedHeaders": true } } ], "version": 4 }

### (2).`launch.json`Need to change MinGW path to actual path```
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "QT-CPPGDB",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/wg_modbus_ats",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}/debug/",
      "environment": [],
      //"symbolSearchPath": "C:\\Symbols",
      "externalConsole": false,
      "linux": {
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      },
      "windows": {
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      },
      "osx": { 
        "miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi", 
        "MIMode": "lldb" 
      },
      // "logging": {
      //     "moduleLoad": false,
      //     "trace": true
      //  },
      "visualizerFile": "my.natvis"
    },
    {
      "name": "CMake-CPPGDB",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/build/${workspaceFolderBasename}", 
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}/build",
      "environment": [],
      //"symbolSearchPath": "C:\\Symbols",
      "externalConsole": false,
      "linux": {
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      },
      "windows": {
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          }
        ]
      },
      "osx": { 
        "miDebuggerPath": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi", 
        "MIMode": "lldb" 
      },
      // "logging": {
      //     "moduleLoad": false,
      //     "trace": true
      //  },
      "visualizerFile": "my.natvis"
    }
  ]
}

(3). tasks.jsonYou can copy the file directly```

{ "version": "2.0.0", // "windows": { // "options": { // "shell": { // "executable": "bash.exe", // "args": ["-c"] // } // } // }, "tasks": [ { "label": "Qmake", "type": "shell", "command": "/usr/local/Trolltech/Qt-4.8.4/bin/qmake", "args": [], "group": "build", "presentation": { "reveal": "silent", "clear": true } }, { "label": "Clean", "type": "shell", "command": "make", "args": [ "clean" ], "group": "build", "presentation": { "reveal": "silent", "clear": true } }, { "label": "MakeCompile", "type": "shell", "dependsOrder": "sequence", "dependsOn": [ "Clean", "Qmake" ], "command": "/usr/bin/make", "args": [ ], "group": "build", "presentation": { // "reveal": "silent", "clear": true } }, ] } ```

REF[1]. https://www.runoob.com/cplusplus/cpp-environment-setup.html

[2]. https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables

[3]. https://zhuanlan.zhihu.com/p/92175757

[4]. https://www.cnblogs.com/bpf-1024/p/11597000.html

[5]. https://zhuanlan.zhihu.com/p/87864677

[C++ environment setup]: https://www.runoob.com/cplusplus/cpp-environment-setup.html[VSCode predefined variables]: https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables[Settings of VScode tasks.json and launch.json]: https://zhuanlan.zhihu.com/p/92175757