There is a way of distributing C/C++ libraries as a one header-only file. Library is in one library.h
file: header declarations together with implementation hidden under #ifdef LIBRARY_IMPL
. You need to create some .c
/.cpp
file that does #define LIBRARY_IMPL; #include "library.h"
which creates compilation unit with implementation.
I have a project which uses such libraries extensively. Project build system creates compile_commands.json
which is then used by clangd
to provide project paths, data structures and hints to VSCode (with llvm-vs-code-extensions.vscode-clangd).
The issue I have is when opening the library.h
file for editing, the symbol LIBRARY_IMPL
is not defined, thus the #ifdef LIBRARY_IMPL
section is treated as comment - without syntax highlighting, type checking etc.
Is there a way to tell clangd
or the extension to treat the file as it was during compilation of the library.c
wrapper file, not stand-alone .h file?