PlatformIO Community

Generating compilation db for library project?

I’ve got a medium-size platformio library project, and I’m trying to get set up do work on it from my beloved emacs. I found that I can generate a compile_commands.json file to give to clangd, and I can successfully generate one in another project that builds binaries, but not in this library-only project. We have tests that build the library, but doing $ pio run -t compiledb yields a json file with only [] in it… Is there any way I can get a useful compilation db out of this? Thanks!

Here’s the whole platformio.ini:

platform = native
test_transport = native
build_flags = -std=c++17
debug_build_flags = -g -DDEBUG
lib_ldf_mode = deep

extends = native
build_type = release

extends = native
build_type = debug

I get the same behavior on a regular platform = native project.

C:\Users\Max\temp\native_c17>pio run -t compiledb
Processing native (platform: native)
Verbose mode can be enabled via `-v, --verbose` option
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Building compilation database .pio\build\native\compile_commands.json
============================================= [SUCCESS] Took 1.11 seconds =============================================
C:\Users\Max\temp\native_c17>cat .pio\build\native\compile_commands.json

please report this as a bug in Issues · platformio/platformio-core · GitHub. When doing this in any other prjoect (e.g. a ststm32 project) I’m getting a much larger file with actual content.

As a workaround you may try to put the library in a mostly empty dummy project that has just enough code to get the firmware compiling (e.g., with the Arduino framework an empty setup() and loop()).

1 Like

Thanks! I’ll make the bug report.

edit: issue #3988

1 Like