VSCode adds header file of C and C++ implementation example

  • 2020-11-18 06:23:41
  • OfStack

When using VSCode to compile C/C++, there will be a situation where you can't find the end of the file. In this case, you need to set two places:

1.c_cpp_properites.json
2.task.json

The following is the corresponding file I modified


{
  "configurations": [
    {
      "name": "Win32",
      "includePath": [
        "${workspaceFolder}/**",
        "${workspaceRoot}",
        "xxx/include"
      ],
      "browse": {
        "path": [
          "${workspaceRoot}",
          "xxx/lib"
        ]
      },
      "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
      ],
      "compilerPath": "xxx/gcc.exe",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "gcc-x64"
    }
  ],
  "version": 4
}

{
  "version": "2.0.0",
  "command": "g++",
  "args": ["-g","${file}","-Lxxx/lib","-Ixxx/include","-o","${fileBasenameNoExtension}.exe"], //  Compile command parameters, add -L . -I options 
  "problemMatcher": {
    "owner": "cpp",
    "fileLocation": ["relative", "${workspaceRoot}"],
    "pattern": {
      "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
      "file": 1,
      "line": 2,
      "column": 3,
      "severity": 4,
      "message": 5
    }
  }
}

Attached launch.json, reference web, link not found, thanks to the original author.


{
  "version": "0.2.0",
  "configurations": [
    
    {
      "name": "(gdb) Launch", //  The configuration name will be displayed in the launch configuration drop-down menu 
      "type": "cppdbg",  //  Configuration type, which can only be cppdbg
      "request": "launch", //  The request configuration type can be launch (start) or attach (attached) 
      "program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",//  The path of the program to be debugged 
      "args": [],  //  The command line parameters passed to the program during debugging, 1 Generally set to null 
      "stopAtEntry": false, //  Set to true When the program will be suspended at the entrance of the program, 1 A set to false
      "cwd": "${workspaceRoot}",//  The working directory in which the program is debugged, 1 As for the ${workspaceRoot} The directory where the code resides 
      "environment": [],
      "externalConsole": true,//  Whether to display the console window when debugging, 1 A set to true Display console 
      "MIMode": "gdb",
      "miDebuggerPath": "xxx\\gdb.exe",// miDebugger I'm going to take the path of theta MinGw Path corresponding to 
      "preLaunchTask": "g++", //  Tasks performed before the start of the debug session, 1 Generally, to compile the program, c++ for g++, c for gcc
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

vscode method to add a header file path

Configuration IntelliSense

The extender will configure the basic information based on the current system environment, so the configuration may be incomplete. In this case, the missing information needs to be configured by generating the c_ES31en_properties.json file:

ctrl+shift+P Open Command Palette, run C/Cpp: Edit configurations... Generate c_cpp_properties. json:


"includePath": [
        "${workspaceFolder}/**",
        "D:\\ite_sdk\\sdk\\**",
        "D:\\ite_sdk\\openrtos\\**",
        "C:\\ITEGCC\\*"

Build the application

If you want to build the application, you need to generate the tasks.json file:

Ctrl+Shift+P - > Tasks: Configure Tasks... - > Create tasks.json file from templates - > Others.


Related articles: