- Select board and generate project
- Add dependencies to
platformio.ini
- Generate
compile_commands.json with pio run -t compiledb
- Check if there are any errors in a sketch with
#include <Arduino.h> related to compiler flags
- Ignore them in the
.clangd configuration file:
CompileFlags:
# Remove the flags that clangd doesn't understand
Remove:
- "-mlongcalls"
- "-fstrict-volatile-bitfields"
- "-fno-tree-switch-conversion"
- Run
pio project metadata to display the necessary Arduino includes for clangd
"toolchain": [
"/home/vic/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0",
"/home/vic/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/xtensa-esp32-elf",
"/home/vic/.platformio/packages/toolchain-xtensa-esp32/lib/gcc/xtensa-esp32-elf/8.4.0/include-fixed",
"/home/vic/.platformio/packages/toolchain-xtensa-esp32/lib/gcc/xtensa-esp32-elf/8.4.0/include",
"/home/vic/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include"
]
- Add these includes to
.clangd
CompileFlags:
# Add the missing system include paths manually
Add:
- "-isystem"
- "/home/vic/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0"
- "-isystem"
- "/home/vic/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/xtensa-esp32-elf"
- "-isystem"
- "/home/vic/.platformio/packages/toolchain-xtensa-esp32/lib/gcc/xtensa-esp32-elf/8.4.0/include-fixed"
- "-isystem"
- "/home/vic/.platformio/packages/toolchain-xtensa-esp32/lib/gcc/xtensa-esp32-elf/8.4.0/include"
- "-isystem"
- "/home/vic/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include"
# Remove the flags that clangd doesn't understand
Remove:
- "-mlongcalls"
- "-fstrict-volatile-bitfields"
- "-fno-tree-switch-conversion"
- Restart
clangd and verify
For compatibility with Arduino IDE, main file must be
.inoand placed in the root project path with same name as it