vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

intelliSenseMode setting is not compatible with compileCommands setting

Open LittleFatHero opened this issue 1 year ago • 3 comments

Environment

  • OS and Version: Ubuntu 22.04
  • VS Code Version: 1.84.2
  • C/C++ Extension Version: 1.18.5
  • If using SSH remote, specify OS of remote machine:

Bug Summary and Steps to Reproduce

Bug Summary: I set the CompileCommands using the compile_commands.json which is generated by arm-none-eabi-gcc/g++ with Cmake and set the intelliSenseMode to gcc-arm, set the compilerPath to /home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-gcc. but when I open a C source file, the OUTPUT windows said that : [12/2/2023, 6:16:23 PM] For C++ source files, IntelliSenseMode was changed from "linux-gcc-arm" to "linux-gcc-x86" based on compiler args and querying compilerPath: "/usr/bin/gcc" [12/2/2023, 6:16:23 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. [12/2/2023, 6:16:23 PM] For C source files, IntelliSenseMode was changed from "linux-gcc-arm" to "linux-gcc-x86" based on compiler args and querying compilerPath: "/usr/bin/gcc" [12/2/2023, 6:16:23 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.

it seems that the imtellisenseMode and compilerPath do not work compatible with compilecommands settings.
why ?

Configuration and Logs

content of settings.json file in the .vscode folder :

{
	"cmake.configureOnOpen": false,
	"C_Cpp.default.compileCommands": "${workspaceFolder}/nuttx/build/compile_commands.json",
	"C_Cpp.default.intelliSenseMode": "gcc-arm",
	"C_Cpp.default.compilerPath": "/home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-gcc",
}

Other Extensions

part of the content of my compile_commands.json is as following:

{ "directory": "/home/dawi/code/nuttxspace/nuttx/build", "command": "/home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-g++ -D__NuttX__ -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/stm32 -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/common -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m -I/home/dawi/code/nuttxspace/nuttx/sched -isystem /home/dawi/code/nuttxspace/nuttx/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include_arch -nostdinc++ -std=c++14 -mtune=cortex-m4 -march=armv7e-m -mfloat-abi=soft -fno-common -Wall -Wshadow -Wundef -nostdlib -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always -Os -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections -funwind-tables -o CMakeFiles/nuttx.dir/empty.cxx.obj -c /home/dawi/code/nuttxspace/nuttx/build/empty.cxx", "file": "/home/dawi/code/nuttxspace/nuttx/build/empty.cxx", "output": "CMakeFiles/nuttx.dir/empty.cxx.obj" }, { "directory": "/home/dawi/code/nuttxspace/nuttx/build", "command": "/home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/stm32 -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/common -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m -I/home/dawi/code/nuttxspace/nuttx/include/cxx -I/home/dawi/code/nuttxspace/nuttx/sched -isystem /home/dawi/code/nuttxspace/nuttx/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include_arch -Wstrict-prototypes -mtune=cortex-m4 -march=armv7e-m -mfloat-abi=soft -fno-common -Wall -Wshadow -Wundef -nostdlib -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always -Os -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections -fdiagnostics-color=always -D__ASSEMBLY__ -DNDEBUG -funwind-tables -o arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_exception.S.obj -c /home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_exception.S", "file": "/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_exception.S", "output": "arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_exception.S.obj" }, { "directory": "/home/dawi/code/nuttxspace/nuttx/build", "command": "/home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/stm32 -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/common -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m -I/home/dawi/code/nuttxspace/nuttx/include/cxx -I/home/dawi/code/nuttxspace/nuttx/sched -isystem /home/dawi/code/nuttxspace/nuttx/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include_arch -Wstrict-prototypes -mtune=cortex-m4 -march=armv7e-m -mfloat-abi=soft -fno-common -Wall -Wshadow -Wundef -nostdlib -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always -Os -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections -fdiagnostics-color=always -D__ASSEMBLY__ -DNDEBUG -funwind-tables -o arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_saveusercontext.S.obj -c /home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_saveusercontext.S", "file": "/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_saveusercontext.S", "output": "arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_saveusercontext.S.obj" }, { "directory": "/home/dawi/code/nuttxspace/nuttx/build", "command": "/home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/stm32 -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/common -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m -I/home/dawi/code/nuttxspace/nuttx/include/cxx -I/home/dawi/code/nuttxspace/nuttx/sched -isystem /home/dawi/code/nuttxspace/nuttx/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include_arch -Wstrict-prototypes -mtune=cortex-m4 -march=armv7e-m -mfloat-abi=soft -fno-common -Wall -Wshadow -Wundef -nostdlib -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always -Os -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections -fdiagnostics-color=always -Wstrict-prototypes -DNDEBUG -funwind-tables -o arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_busfault.c.obj -c /home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_busfault.c", "file": "/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_busfault.c", "output": "arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_busfault.c.obj" }, { "directory": "/home/dawi/code/nuttxspace/nuttx/build", "command": "/home/dawi/arm_gnu_toolchains/bin/arm-none-eabi-gcc -D__KERNEL__ -D__NuttX__ -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/stm32 -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/common -I/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m -I/home/dawi/code/nuttxspace/nuttx/include/cxx -I/home/dawi/code/nuttxspace/nuttx/sched -isystem /home/dawi/code/nuttxspace/nuttx/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include -isystem /home/dawi/code/nuttxspace/nuttx/build/include_arch -Wstrict-prototypes -mtune=cortex-m4 -march=armv7e-m -mfloat-abi=soft -fno-common -Wall -Wshadow -Wundef -nostdlib -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always -Os -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections -fdata-sections -fdiagnostics-color=always -Wstrict-prototypes -DNDEBUG -funwind-tables -o arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_cache.c.obj -c /home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_cache.c", "file": "/home/dawi/code/nuttxspace/nuttx/arch/arm/src/armv7-m/arm_cache.c", "output": "arch/CMakeFiles/arch.dir/arm/src/armv7-m/arm_cache.c.obj" },

Additional context

No response

LittleFatHero avatar Dec 02 '23 13:12 LittleFatHero

compile_commands.json should be picked up unless you have a compilerPath set in c_cpp_properties.json or if there’s some error in querying the compiler. Could you please provide the log diagnositics via the C/C++: Log Diagnostics command to provide more context?

browntarik avatar Dec 05 '23 18:12 browntarik

As a workaround, you should be able to set the compilerPath in c_cpp_properties.json

browntarik avatar Dec 05 '23 18:12 browntarik

I believe this may be addressed in 1.19.3. If I understand correctly, there are two issues that may be related:

  1. When a compilerPath is specified, it should override the compiler in compile_commands.json. (This was originally intended as a work-around, but we're considering changing this behavior. This is tracked by https://github.com/microsoft/vscode-cpptools/issues/11889 ). However, there is a bug preventing that compilerPath from being conbined with the compiler arguments in compile_commands.json to properly resolve the configuration. In 1.19.3, this should be fixed such that it combines the compilerPath with the args from compile_commands.json properly. By specifying the same compiler in both compile_commands.json and your base configuration, that ensures both configurations from compile_commands.json work as expected, and files not found in compile_commands.json get configured properly to use the compilerPath in their base configuration. (Whereas, if the compilerPath were not present, it would fall back to some default detected compiler.)

  2. There was an issue with those IntelliSenseMode was changed from messages being reported for compiler queries based on compile_commands.json entries. Since IntelliSenseMode is specific to the base configuration, there should be no such warning when resolving compile_commands.json entries. Those incorrect warnings will be removed in 1.19.3.

Colengms avatar Feb 01 '24 23:02 Colengms

This should be addressed in 1.19.4. If you're still seeing an issue with >=1.19.4, let us know.

Colengms avatar Feb 22 '24 03:02 Colengms