Home >Backend Development >C++ >Should I Specify Include Paths in Both `c_cpp_properties.json` and `task.json` for VSCode C Development?
The Use of c_cpp_properties.json and task.json
In VSCode, IntelliSense utilizes c_cpp_properties.json's includePath to locate header files for auto-completion. However, when compiling code, developers often encounter the need to explicitly specify include paths in task.json as well.
Query 1: Appropriate Configuration for C Tasks
Should include directories and libraries be specified in both c_cpp_properties.json and task.json? The answer is yes, as the build system and the editor operate independently in VSCode, both requiring access to this information.
Recommendation:
To maintain portability across build environments, it's best to avoid directly specifying include paths in task.json. Instead, consider using a separate build system that can be invoked from the command line and referenced within task.json.
Query 2: Understanding includePath and browse
VSCode provides two systems for interpreting C code: the deprecated "Tag Parser" and the newer "Intellisense." includePath is utilized by Intellisense, while browse.path is used by Tag Parser.
Recommendation:
For optimal accuracy and compatibility, we strongly recommend disabling Tag Parser in Settings → C/C → Intelli Sense Engine. By setting the engine to "Default," you'll ensure that Intellisense handles C interpretation.
Example Configuration:
The provided c_cpp_properties.json configures IntelliSense with the necessary include paths:
{ "configurations": [ { ... "includePath": [ "${workspaceFolder}/**", "D:/github/dependencies/SDL2-2.0.8/include" ], ... } ], ... }
The corresponding task.json, configured to invoke the GNU Make utility, would look like this:
{ ... "tasks": [ { "label": "build", "type": "shell", "command": "make", "args": [] } ], ... }
Conclusion:
The dual inclusion of include paths in c_cpp_properties.json and task.json is a necessity in VSCode. However, leveraging a dedicated build system and prioritizing Intellisense over Tag Parser will greatly enhance your C development experience.
The above is the detailed content of Should I Specify Include Paths in Both `c_cpp_properties.json` and `task.json` for VSCode C Development?. For more information, please follow other related articles on the PHP Chinese website!