Open shac12 opened 3 years ago
Are you using a compile_commands.json
file?
Are you using a
compile_commands.json
file?
Hi thanks for replying so quickly.
I don't think so. Nothing in the ros documentation talks about a compile commands file but it's possible that this has been abstracted away from us by the Catkin tool.
Also it should be noted that everything compiles with Catkin build normally with no errors.
You need to either manually tell clang-tidy where to find your headers or have your build system generate a compile_commands.json
file.
I'm not sure what build system you're using, but I know CMake can generate a compile_commands.json
file. Just pass -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
on the command line. Alternatively, the cmake-tools extension has a setting for that. If you're not using CMake or another tool that can generate this file for you, you'll have to list your includes manually.
According to the clang-tidy docs, it looks like you have to pass the include paths to clang itself. The provide the following example: clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...
https://clang.llvm.org/extra/clang-tidy/
I think you should be able to do this using the clang-tidy.compilerArgs
setting.
Thank you so much for the help.
The way that our project is structured is that there are a number of cmake packages that all depend on ROS. Catkin goes through each of these packages and builds them using cmake and their cmake lists. Is there a way to programmatically set clang to look for these ROS headers for all of these packages ? For example, An environment variable I can tweak to get clang to look in the right places ?
I will try what you have mentioned shortly when I get to work and I'll be sure to post back with the results.
Is there a way to programmatically set clang to look for these ROS headers for all of these packages? For example, An environment variable I can tweak to get clang to look in the right places?
Other than PATH
? I have no idea. This is just a plugin that integrates clang-tidy into vscode. You'll have to look at the clang docs for that.
I see this too even with a compile_commands.json file (which the ms cpp plugin picks up fine).
Not 100% ideal, but I solved this by setting clang-tidy.buildPath
to the compile_commands.json
folder (variables like ${workspaceFolder}
don't seem to work, but that's somewhat expected):
A good way to enable CMAKE_EXPORT_COMPILE_COMMANDS
by default is to put it into your configurationPresets
's cacheVariables
property in your project's CMakePresets.json
. In a pinch you can also change the setting temporarily (until the next clean build) in your CMakeCache.txt
.
Thanks so much for this great extension! :smiley:
When working in a ROS Catkin workspace, intellisense is able to find all my header files, yet clang complains that it cannot find them. It does not complain about std headers such as vector or sstream but it cannot find ros specific header files.
My cpp properties are:
My settings.json is:
My user settings are as follows: