cancel
Showing results for 
Search instead for 
Did you mean: 

clangd not resolving preprocessor defines

christianegerer
Associate

I'm experiencing some issues with indexing of clangd. I'm working on a project including Bluetooth LE and the ble_types.h header file makes extensive use of the preprocessor define __PACKED_STRUCT which is defined in one of the CMSIS compiler header files (e.g., cmsis_gcc.h for GCC compiler). clangd is for some reason not able to resolve the typedefs using __PACKED_STRUCT which makes code browsing harder and auto-completion does not work for these types.

I found a workaround by adding the __PACKED_STRUCT define explicitly in the .clangd config file.

My current .clangd file looks as follows:

CompileFlags:
  Add:
    - '-ferror-limit=0'
    - '-Wno-implicit-int'
    - '-D__PACKED_STRUCT=struct __attribute__((packed, aligned(1)))'
  CompilationDatabase: build/Debug
Diagnostics:
  Suppress:
    - unused-includes
    - unknown_typename
    - unknown_typename_suggest
    - typename_requires_specqual
Completion:
  HeaderInsertion: Never

So I basically added the preprocessor define to the CompileFlags. Of course this is not universal now and only valid for GCC. Also any other preprocessor defines would need to be added manually.

I also have automatic header insertion disabled since this caused issues.

I'm wondering if anyone else experiences similar issues and if there is a cleaner way to solve it?

1 REPLY 1
Nawres GHARBI
ST Employee

Hi @christianegerer 

unfortunately I'm not able to reproduce could you please attach an example project with the issue you described