#220 Official STM32 showing many undeclared identifiers

this thread is a follow up on some investigations in

as i'm trying to figure out the root cause
compile_commands.json

[]

pretty much an empty file
the specs for that seem to be here
https://clang.llvm.org/docs/JSONCompilationDatabase.html
perhaps i'd try to define a compile_commands.json manually and try the autocomplete again?
apparently clangd does some form of 'background indexing'
accordingly compile_commands.json is needed
https://clangd.llvm.org/installation.html
any hints on how to go about with this? e.g. should i replace that in
arduino-language-server5444..../compile_commands.json
and restart the IDE?

part of the manal troubleshooting logs followed up in this thread

1 Like

i made a minor progress here. it turns out arduino-cli now generates compile_commands.json in the build folder
arduino/arduino-cli#849
e.g. /tmp/arduino-sketch-33482DDA232A7A14.../compile_commands.json

[
 {
  "directory": "/opt1/arduino/arduino-ide_2.0.0-beta.4-snapshot.51195eb_Linux_64bit",
  "arguments": [
   "/opt1/arduino/dotarduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/arm-none-eabi-g++",
   "-mcpu=cortex-m4",
   "-mfpu=fpv4-sp-d16",
   "-mfloat-abi=hard",
   "-mthumb",
   "@/tmp/arduino-sketch-33482DDA232A7A142FE6DC7A771F0016/sketch/build_opt.h",
user@snoopy1:/tmp/arduino-sketch-33482DDA232A7A142FE6DC7A771F0016> head -30 compile_commands.json 
[
 {
  "directory": "/opt1/arduino/arduino-ide_2.0.0-beta.4-snapshot.51195eb_Linux_64bit",
  "arguments": [
   "/opt1/arduino/dotarduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/arm-none-eabi-g++",
   "-mcpu=cortex-m4",
   "-mfpu=fpv4-sp-d16",
   "-mfloat-abi=hard",
   "-mthumb",
   "@/tmp/arduino-sketch-33482DDA232A7A142FE6DC7A771F0016/sketch/build_opt.h",
   "-c",
   "-Os",
   "-w",
   "-std=gnu++14",
   "-ffunction-sections",
   "-fdata-sections",
   "-nostdlib",
   "-fno-threadsafe-statics",
   "--param",
   "max-inline-insns-single=500",
   "-fno-rtti",
   "-fno-exceptions",
   "-fno-use-cxa-atexit",
   "-MMD",
   "-I/home/user/Arduino/sketch_mar28b",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/avr",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/LL",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/usb",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/OpenAMP",

pretty large file, i tried copying
/tmp/arduino-sketch-33482DDA232A7A14.../compile_commands.json to
/tmp/arduino-language-server19487.../compile_commands.json
replacing the empty file.
unfortunately that didn't solve the issue, i try clicking verify/compile but the results is quite similar
many of the symbols gives a 'no definition found' if i right clicked and select goto definition.
should i exit arduino-ide and restart
/tmp/arduino-language-server19487..
folder is deleted and recreated with an empty compile_commands.json

the language server toolchain architecture apparently seem to be
arduino-ide2 -> vscode-arduino-tools (module) -> arduino-language-server -> clangd
in inols-err.log
--> initialize(file:///home/user/Arduino/sketch_mar28b)
running: /opt1/arduino/arduino-ide_2.0.0-beta.4-snapshot.51195eb_Linux_64bit/resources/app/node_modules/arduino-ide-extension/build/arduino-cli compile --fqbn STM32:stm32:GenF4 --only-compilation-database --clean --source-override /tmp/071191930 --build-path /tmp/arduino-language-server071191930 --format json /home/user/Arduino/sketch_mar28b

hence compile_commands.json is actually generated by arduino-cli using the --only-compilation-database option
i went into /tmp/arduino-language-server071191930 and tried

/opt1/arduino/arduino-ide_2.0.0-beta.4-snapshot.51195eb_Linux_64bit/resources/app/node_modules/arduino-ide-extension/build/arduino-cli compile --fqbn STM32:stm32:GenF4 --only-compilation-database --clean --build-path . --format json /home/user/Arduino/sketch_mar28b
{
"compiler_out": "",
"compiler_err": "arm-none-eabi-g++: error: ./sketch/build_opt.h: No such file or directory\n",
"builder_result": {
"build_path": "."
},
"success": false
}

^^^ in running the above command i've removed the source override option and did the compilation in the /tmp/arduino-language-server071191930 directory
however if I remove --only-compilation-database option the build completes, though with a success : false status

/opt1/arduino/arduino-ide_2.0.0-beta.4-snapshot.51195eb_Linux_64bit/resources/app/node_modules/arduino-ide-extension/build/arduino-cli compile --fqbn STM32:stm32:GenF4 --clean --build-path . --format json /home/user/Arduino/sketch_mar28b{
"compiler_out": "Couldn't deeply cache core build: Rel: can't make . relative to /tmp/arduino-core-cache\nRunning normal build of the core...\n",
"compiler_err": "",
"builder_result": {
"build_path": "."
},
"success": false
}

and it successfully generates a compile_commands.json

[
 {
  "directory": "/tmp/arduino-language-server071191930",
  "arguments": [
   "/opt1/arduino/dotarduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/arm-none-eabi-g++",
   "-mcpu=cortex-m4",
   "-mfpu=fpv4-sp-d16",
   "-mfloat-abi=hard",
   "-mthumb",
   "@./sketch/build_opt.h",
   "-c",
   "-Os",
   "-w",
   "-std=gnu++14",
   "-ffunction-sections",
   "-fdata-sections",
   "-nostdlib",
   "-fno-threadsafe-statics",
   "--param",
   "max-inline-insns-single=500",
   "-fno-rtti",
   "-fno-exceptions",
   "-fno-use-cxa-atexit",
   "-MMD",
   "-I/home/user/Arduino/sketch_mar28b",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/avr",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/LL",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/usb",
   "-I/opt1/arduino/dotarduino15/packages/STM32/hardware/stm32/1.9.0/cores/arduino/stm32/OpenAMP",
...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.