From documentation : -p is used to read a compile command database. For example, it can be a CMake build directory in which a file named compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get this output). When no build path is specified, a search for compile_commands.json will be attempted through all parent paths of the first input file . See: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree. Answer from the_poope on reddit.com
🌐
GitHub
github.com › microsoft › vscode-cpptools › issues › 13207
clang-tidy and passing Include paths · Issue #13207 · microsoft/vscode-cpptools
January 28, 2025 - Feature request when using clang-tidy. I have a VS Code project using C++ with has include directories listed in the c_cpp_properties.json. I am also using the CMake Tools extension in use to build the project. From my understanding if you set the configurationProvider, which I have as ms-vcode.cmake-tools, then the includePath set in c_cpp_properties will be ignored.
Author   microsoft
🌐
GitHub
github.com › microsoft › vscode-cpptools › issues › 9032
Include paths from c_cpp_properties.json are not passed to clang-tidy for code analysis · Issue #9032 · microsoft/vscode-cpptools
March 16, 2022 - I have a c_cpp_properties.json file defined in the repo and it contains quite a few entries under includePath. Those include paths are not passed to clang-tidy when I run the code analysis and so I always have errors with not found heade...
Author   microsoft
🌐
Reddit
reddit.com › r/cpp › clang-tidy support in vscode is possible
r/cpp on Reddit: clang-tidy support in VSCode is possible
October 21, 2020 -

if you're an exceptionally attractive individual like me, the only things preventing you from retiring clion and adopting vscode (for everything) are clang-tidy and cppcheck. we can get clang-tidy by upvoting this feature request for adding clang-tidy support to the cpp extension for vscode: https://github.com/microsoft/vscode-cpptools/issues/2908

clang-tidy good. more clang-tidy.

🌐
Microsoft
devblogs.microsoft.com › dev blogs › c++ team blog › visual studio code c++ december 2021 update: clang-tidy
Visual Studio Code C++ December 2021 Update: clang-tidy - C++ Team Blog
December 21, 2021 - Nope! Clang-tidy now comes bundled with the C++ extension. But if you already have clang-tidy installed (and it’s on your environment’s path), the C++ extension will use that one instead.
🌐
GitHub
github.com › notskm › vscode-clang-tidy
GitHub - notskm/vscode-clang-tidy · GitHub
March 25, 2023 - Equivalent to clang-tidy -p /path
Starred by 51 users
Forked by 29 users
Languages   TypeScript
🌐
Reddit
reddit.com › r/cpp_questions › vscode & clang-tidy and other tools
r/cpp_questions on Reddit: VScode & clang-tidy and other tools
November 9, 2024 -

Hello,

I am working through various complaints from clang-tidy, clang and cppcheck. I have a couple questions with a Vulkan CMake project . I am having a bit of time setting everything properly. Note everything builds with Cmake.

  1. with Clang-tidy I know of the .clang-tidy file in project root directory. But I am not understanding how to let clang-tidy know of the Include paths. It is finding the Vulkan header files though I at this point I am not certain how. However it is not finding GLFW/glfw3.h header files. I am at a loss of how to proceed. CoPilot mentions compile_commands.json but creating one has not solved my problem.

  2. flylint has a number of settings including for includePaths. The questions will clang and cppcheck inherit the includePaths setting from the flylint.includePaths variable or do I have to set those all separately . Of course this course if inheritance should apply to a number of other flylint variables.

Thanks,

Frank

🌐
GitHub
github.com › alesiong › clang-tidy-linter
GitHub - alesiong/clang-tidy-linter: A Visual Studio Code extension to lint code by clang-tidy. · GitHub
You have to modify clangTidy.extraCompilerArgs setting if your C/C++ project has custom include paths. Repository: https://github.com/alesiong/clang-tidy-linter · I'm a beginner to vscode extension development, so if you have any suggestions, don't hesitate to post issues and/or pull requests.
Starred by 17 users
Forked by 9 users
Languages   TypeScript
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › code-quality › clang-tidy
Using Clang-Tidy in Visual Studio | Microsoft Learn
For example: -std=c++20;-DMY_DEFINE=1;-Ipath\to\include. The Clang-Tidy Prepend Additional Options property lets you specify compiler arguments that are passed to Clang-Tidy using the --extra-args-before command-line option. These arguments are inserted before the default compiler arguments when Clang-Tidy parses your code. Enter arguments as a semi-colon separated list. For example: -std=c++20;-DMY_DEFINE=1;. The Max Number of Processes property lets you specify how many processes Clang-Tidy can use to run analysis in parallel.
🌐
GitHub
github.com › fbaeuerlein › cpp-vscode-guide › issues › 23
Configuration for clang-tidy with include paths · Issue #23 · fbaeuerlein/cpp-vscode-guide
March 10, 2020 - Clang tidy finds errors if the include paths are missing (e.g. at tests). Find a possible configuration to avoid this
Author   fbaeuerlein
Find elsewhere
Top answer
1 of 3
36

If you are using CMake, VSCode has CMake plugins to help you build the project. So you do not need to modify the settings.json. Just use:

include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") 

Or if there are no other modules used the header files in that folder you could use something like:

target_include_directories(MyHelper "${CMAKE_CURRENT_SOURCE_DIR}/include") 

If you only need the project be built successfully. That is the whole story.

In the case of that, you got some little green zigzag lines under the #include statements hurting your eyes. You need to generate c_cpp_properties.json. It has nothing to do with helping the compiler to build the code but for helping VSCode intellisense to realize the existence of libraries and header files. And again, you are able to leverage the CMake by adding CMake options in the CMakeLists.txt:

add_definitions(-DCMAKE_EXPORT_COMPILE_COMMANDS=ON)

The CMake will generate a file compile_commands.json under your build directory. The VSCode is able to parse the Json file and find the include path based on the content in that file. So what you need to do is just letting VSCode know where is the Json file. You can do that by adding follwing line in the c_cpp_properties.json:

 "configurations": [
        {
            "name": "Mac",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json",
            ...
        }],

Rebuild the project will let the VSCode intellisense find all necessary paths.

[Environment]
Ubuntu: 16.04.3
VSCode: 1.23.1
VSCode plugins: C/C++ 0.17.0, CMAKE 0.0.17, CMakeTools 0.11.1

2 of 3
6

Okay, this was foolish, but in the event someone uses Visual Studio Code and does not have a trivial project. These instructions are assuming you're using clang compiler:

  1. Open your project directory
  2. Open .vscode/settings.json
  3. Configure the line below inside of the JSON object:

    // Compiler options for C++ (e.g. ['-std=c++11'])
    "clang.cxxflags": [
        "-I/path/to/my/include/directory" // header files
    ],
    
🌐
Visual Studio Code
code.visualstudio.com › docs › cpp › config-clang-mac
Using Clang in Visual Studio Code
November 3, 2021 - Visual Studio Code places these settings in .vscode/c_cpp_properties.json. If you open that file directly, it should look something like this: { "configurations": [ { "name": "Mac", "includePath": ["${workspaceFolder}/**"], "defines": [], "macFrameworkPath": [ "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" ], "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "macos-clang-arm64" } ], "version": 4 }
🌐
GitHub
github.com › microsoft › vscode-cmake-tools › issues › 3240
Unable to set a header path as -isystem in clang-tidy? · Issue #3240 · microsoft/vscode-cmake-tools
July 17, 2023 - C_Cpp settings (taken from workspace file, as I do not have a c_cpp_properties.json): "C_Cpp.clang_format_style": "file:${workspaceFolder}/XXXX/vscode/.clang-format", "C_Cpp.codeAnalysis.clangTidy.args": [ "--config-file=${workspaceFolder}/XXXX/vscode/.clang-tidy" ], "C_Cpp.codeAnalysis.exclude": { // Various paths of 3rd party generated code. }, "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "C_Cpp.vcpkg.enabled": false, -------- Diagnostics - 7/17/2023, 1:29:49 PM Version: 1.16.3 Current Configuration: { "name": "Linux", "includePath": [ "XXXX/master/**" ], "defines": [], "c
Author   microsoft
🌐
GitHub
github.com › IARSystems › iar-vsc-build › issues › 40
Include paths not set up to use clang-tidy · Issue #40 · iarsystems/iar-vsc-build
March 1, 2023 - I like to use clang-tidy as my static analysis tool inside VS Code. This extension does not initialize the include paths that are needed for it, or any other extension needing paths to work properly since the proper header files annot be found.
Author   iarsystems
🌐
GitHub
github.com › microsoft › vscode-cpptools › issues › 9574
Code Analysis with useBuildPath=true gives 'stddef.h' file not found unless clangTidy.path is changed · Issue #9574 · microsoft/vscode-cpptools
July 12, 2022 - I recall the missing path is something like /usr/lib/llvm-10/lib/clang/10.0.0/include -- when clang 10 is installed on the machine...it's possibly related to the fact that we build clang 14 and it's possible the issue may not repro if the matching version of the /usr/lib/llvm- is installed. A user report is at #9555, but it got morphed into a bug on relative paths. ... Feature: Code AnalysisRelated to integration with clang-tidy, cppcheck, cl.exe /analyze, etc.Related to integration with clang-tidy, cppcheck, cl.exe /analyze, etc.Language Servicebug
Author   microsoft
🌐
YouTube
youtube.com › microsoft developer
clang-tidy in Visual Studio Code - YouTube
Sign up for Pure Virtual C++ 2022, a free one-day virtual conference for the whole C++ community running on April 26th: https://aka.ms/pure-virtual-cppclang-...
Published   April 21, 2022
Views   19K
🌐
Reddit
reddit.com › r/c_programming › make include directories (with compiler option -i) known to clangd / clang-tidy (vs extensions)
r/C_Programming on Reddit: Make include directories (with compiler option -I) known to clangd / clang-tidy (VS extensions)
February 21, 2024 -

I use Codium with the clangd and clang-tidy extensions; However, I can't find any info on how to tell these programs to find header files in the "src" and "lib" directories; which I include, for example like #include <foo/bar.h> (compiled with the options -I lib -I src)

I don't want to have to laboriously insert header files using ../../../foo/bar.h ... and I certainly don't want to miss out on the support provided by the Codium extensions mentioned.

🌐
Reddit
reddit.com › r/vscode › vscode & clang-tidy and other tools
r/vscode on Reddit: VScode & clang-tidy and other tools
November 8, 2024 -

Hello,

I am working through various complaints from clang-tidy, clang and cppcheck. I have a couple questions with a Vulkan CMake project . I am having a bit of time setting everything properly. Note everything builds with Cmake.

  1. with Clang-tidy I know of the .clang-tidy file in project root directory. But I am not understanding how to let clang-tidy know of the Include paths. It is finding the Vulkan header files though I at this point I am not certain how. However it is not finding GLFW/glfw3.h header files. I am at a loss of how to proceed. CoPilot mentions compile_commands.json but creating one has not solved my problem.

  2. flylint has a number of settings including for includePaths. The questions will clang and cppcheck inherit the includePaths setting from the flylint.includePaths variable or do I have to set those all separately . Of course this course if inheritance should apply to a number of other flylint variables.

Thanks,

Frank

🌐
GitHub
github.com › microsoft › vscode-cpptools › discussions › 12571
how to configure clang-tidy in a complicated cross-compile build environment · microsoft/vscode-cpptools · Discussion #12571
(we've experimented with "--extra-arg=--target=aarch64" in the clang-tidy args, and toggling useBuildPath both ways, with no success, it just seems to push the problem around to slightly different output of header/include warnings). Thanks in advance! -Eric. relevant VSCode/Clang-tidy config from workspace settings.json: "C_Cpp.loggingLevel": "Debug", "C_Cpp.default.cppStandard": "c++17", "C_Cpp.codeAnalysis.clangTidy.useBuildPath": true, "C_Cpp.codeAnalysis.clangTidy.enabled": true, "C_Cpp.codeAnalysis.exclude": { "externals/**": true, "build/**": true }, "C_Cpp.codeAnalysis.clangTidy.path": "/usr/bin/clang-tidy-10", "C_Cpp.codeAnalysis.clangTidy.args": [ "--extra-arg=-mno-sse2", ], Clang-tidy gives zero warnings when building x86_64.
Author   microsoft
🌐
Maximilianmbeck
maximilianmbeck.com › post › clang-tidy_vs-code
maximilianmbeck.com - maximilianmbeck Resources and Information.
April 26, 2021 - maximilianmbeck.com is your first and best source for all of the information you’re looking for. From general topics to more of what you would expect to find here, maximilianmbeck.com has it all. We hope you find what you are searching for!