Closed parsley72 closed 10 months ago
Replying to @Colengms question here, I'm not sure what locate
has to do with this if I'm specifying the path in .vscode/c_cpp_properties.json
?
I've found a way around this problem - get rid of .vscode/c_cpp_properties.json
and just put all the entries in .vscode/settings.json
under C_Cpp.default.
. So my settings file now looks like:
{
"C_Cpp.default.includePath": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/include/**",
"${workspaceFolder}/oe-workdir/recipe-sysroot/usr/**"
],
"C_Cpp.default.defines": [],
"C_Cpp.default.compilerPath": "${workspaceFolder}/oe-workdir/recipe-sysroot-native/usr/bin/aarch64-oclea-linux/aarch64-oclea-linux-gcc",
"C_Cpp.default.cStandard": "c17",
"C_Cpp.default.cppStandard": "gnu++17",
"C_Cpp.default.intelliSenseMode": "linux-gcc-arm64",
"C_Cpp.default.compileCommands": "${workspaceFolder}/.vscode/compile_commands.json"
}
I wonder if WSL2 isn't picking up the "Linux" section in c_cpp_properties.json properly?
Just noticed that now I've moved everything to .vscode/settings.json
, when I open the project in the "C/C++ Configuration Warnings" output window I get:
[9/4/2023, 2:44:24 PM] For C++ source files, IntelliSenseMode was changed from "linux-gcc-arm64" to "linux-gcc-x64" based on compiler args and querying compilerPath: "/usr/bin/gcc"
[9/4/2023, 2:44:24 PM] IntelliSenseMode was changed because it didn't match the detected compiler. Consider setting "compilerPath" instead. Set "compilerPath" to "" to disable detection of system includes and defines.
[9/4/2023, 2:44:24 PM] For C source files, IntelliSenseMode was changed from "linux-gcc-arm64" to "linux-gcc-x64" based on compiler args and querying compilerPath: "/usr/bin/gcc"
[9/4/2023, 2:44:24 PM] IntelliSenseMode was changed because it didn't match the detected compiler. Consider setting "compilerPath" instead. Set "compilerPath" to "" to disable detection of system includes and defines.
Not sure what effect that has, but it's better than not finding the headers so I'll leave it like this. But either way something isn't working properly.
You shouldn't need to delete your c_cpp_properties.json
to make this work. If you are compiling with a specific sysroot and IntelliSense isn't picking it up for some reason, I would recommend adding that to the compilerArgs
property instead of the includePath
because gcc/clang compilers have a specific default include path ordering that we want the language server to pick up.
I would normally recommend trying something like this, but I just noticed that you have a compile_commands.json
and our language server prefers taking source file configurations from there over the compilerPath
/compilerArgs
/includePath
properties:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/",
"${workspaceFolder}/app/",
],
"defines": [],
"compilerPath": "${workspaceFolder}/oe-workdir/recipe-sysroot-native/usr/bin/aarch64-oclea-linux/aarch64-oclea-linux-gcc",
"compilerArgs": [
"--sysroot",
"${workspaceFolder}/oe-workdir/recipe-sysroot"
]
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-arm64",
"compileCommands": "${workspaceFolder}/.vscode/compile_commands.json"
}
],
"version": 4
}
Can you share the compile_commands entry for the source file that is showing red squiggles for you? We'll see if there are any clues there.
That seems to fix the red sqiggles and I'm not seeing anything in the "C/C++ Configuration Warnings" output window.
I'm not sure what locate has to do with this if I'm specifying the path in .vscode/c_cpp_properties.json?
Hi @parsley72 . If your c_cpp_properties.json
file contains a compileCommands
entry, that will take precedence over all other fields, for any files found in that compile_commands.json
file. (Header files included to by source files in compile_commands.json
will also use that source file's compile_commands.json
entry to configure IntelliSense). That would explain why changes you've made to include paths, etc., may not appear to be effective. It would also seem to imply that configuration issues you're seeing are either due to issues with the contents of the compile_commands.json
file, or perhaps some arguments on those command lines that are not being parsed properly. Are you successfully able to build using your compile_commands.json
file?
Since you mentioned using CMake, I'd suggest using the CMake Tools extension, and specifying it as a configurationProvider
(which will also take precedence over other configuration fields).
Note that "#include errors detected. Consider updating your compile_commands.json or includePath. Squiggles are disabled for this translation unit"
is not related to "Code Analysis". That error message is coming from IntelliSense. Whereas, "Code Analysis" involves invoking clang-tidy
, a 3rd party tool which, coincidentally, leverages your compile_commands.json
file directly. But it sounds like both are exhibiting a similar 'file not found' error.
@Colengms I think you missed my comment above - adding the --sysroot
to compilerArgs
seems to have fixed my problem. If compile_commands.json
is overriding these then I have no idea how this is making a difference.
Hi @parsley72 . That would seem to imply that the file you are repro'ing with was not successfully found in compile_commands.json
. If it were, paths from your base configuraiton would not have been used. The output of the C/C++: Log Diagnostics
command, while that file is opened, should indicate whether a compiler_commands.json
entry was used to configure the file or not.
This issue has been closed because it needs more information and has not had recent activity.
Environment
Bug Summary and Steps to Reproduce
Bug Summary: Code Analysis is failing to find headers referenced in the code.
Steps to reproduce: I can't give you source code because it's proprietary but I'm using Yocto to build a CMake project.
Both headers are underlined with the error "cannot open source file" and the file shows the error "#include errors detected. Consider updating your compile_commands.json or includePath. Squiggles are disabled for this translation unit" I can run
find oe-workdir/recipe-sysroot/usr -name filesystem
(the include path specified below) and getoe-workdir/recipe-sysroot/usr/include/c++/9.5.0/filesystem
back, so I know it's there.Expected behavior: Headers should be found. What's odd is that I have SonarLint installed which seems to find the headers fine.
Configuration and Logs
Other Extensions
No response
Additional context
No response