#include <cassert> in assert.h causes error with clangd #3181

Open
opened 2026-09-05 12:26:47 -05:00 by ancientstraits · 3 comments
ancientstraits commented 2026-09-05 12:26:47 -05:00 (Migrated from github.com)

I like to use the clangd language server with my projects,
but a problem arises when using it for a C++ project that uses pico-sdk.
Even when using the correct compile-commands.json, I cannot remove this error.

The error is:

In included file: 'cassert' file not found

The only way for me to remove this message is to remove the #include <cassert> in src/common/pico_base_headers/include/pico/assert.h. If I #include <assert.h> instead, there is no error, and I still can use the assert macro.

Does pico-sdk include C++ headers anywhere else, or is it only for <cassert>?

I like to use the clangd language server with my projects, but a problem arises when using it for a C++ project that uses pico-sdk. Even when using the correct compile-commands.json, I cannot remove this error. The error is: ``` In included file: 'cassert' file not found ``` The only way for me to remove this message is to remove the `#include <cassert>` in `src/common/pico_base_headers/include/pico/assert.h`. If I `#include <assert.h>` instead, there is no error, and I still can use the `assert` macro. Does pico-sdk include C++ headers anywhere else, or is it only for `<cassert>`?
lurch commented 2026-09-06 06:34:45 -05:00 (Migrated from github.com)

Does this cause a build-time error, or only an error from the "clangd language server"?

Does pico-sdk include C++ headers anywhere else, or is it only for <cassert>?

A quick grep finds:

$ git grep -E '^#include <[^\.]+>'
src/common/pico_base_headers/include/pico/assert.h:#include <cassert>
src/host/hardware_sync/include/hardware/sync.h:#include <atomic>
src/rp2_common/pico_clib_interface/llvm_libc_interface_cpp.cpp:#include <version>
src/rp2_common/pico_clib_interface/llvm_libc_interface_cpp.cpp:#include <cstdarg>
src/rp2_common/pico_cxx_options/new_delete.cpp:#include <cstdlib>
test/kitchen_sink/kitchen_sink_cpp.cpp:#include <vector>
tools/pioasm/ada_output.cpp:#include <algorithm>
tools/pioasm/ada_output.cpp:#include <iostream>
tools/pioasm/ada_output.cpp:#include <sstream>
tools/pioasm/c_sdk_output.cpp:#include <algorithm>
tools/pioasm/c_sdk_output.cpp:#include <iostream>
tools/pioasm/c_sdk_output.cpp:#include <sstream>
tools/pioasm/go_output.cpp:#include <algorithm>
tools/pioasm/go_output.cpp:#include <iostream>
tools/pioasm/go_output.cpp:#include <sstream>
tools/pioasm/hex_output.cpp:#include <iostream>
tools/pioasm/json_output.cpp:#include <algorithm>
tools/pioasm/json_output.cpp:#include <iostream>
tools/pioasm/main.cpp:#include <iostream>
tools/pioasm/output_format.h:#include <cstdint>
tools/pioasm/output_format.h:#include <vector>
tools/pioasm/output_format.h:#include <map>
tools/pioasm/output_format.h:#include <string>
tools/pioasm/output_format.h:#include <memory>
tools/pioasm/pio_assembler.cpp:#include <cstdio>
tools/pioasm/pio_assembler.cpp:#include <iterator>
tools/pioasm/pio_assembler.h:#include <algorithm>
tools/pioasm/pio_disassembler.cpp:#include <array>
tools/pioasm/pio_disassembler.cpp:#include <sstream>
tools/pioasm/pio_disassembler.cpp:#include <iomanip>
tools/pioasm/pio_disassembler.h:#include <string>
tools/pioasm/pio_disassembler.h:#include <cstdint>
tools/pioasm/pio_types.h:#include <cstdint>
tools/pioasm/pio_types.h:#include <string>
tools/pioasm/pio_types.h:#include <map>
tools/pioasm/pio_types.h:#include <set>
tools/pioasm/pio_types.h:#include <utility>
tools/pioasm/pio_types.h:#include <vector>
tools/pioasm/pio_types.h:#include <memory>
tools/pioasm/python_output.cpp:#include <array>
tools/pioasm/python_output.cpp:#include <algorithm>
tools/pioasm/python_output.cpp:#include <sstream>
tools/pioasm/python_output.cpp:#include <iomanip>
Does this cause a build-time error, or only an error from the "clangd language server"? > Does pico-sdk include C++ headers anywhere else, or is it only for `<cassert>`? A quick grep finds: ``` $ git grep -E '^#include <[^\.]+>' src/common/pico_base_headers/include/pico/assert.h:#include <cassert> src/host/hardware_sync/include/hardware/sync.h:#include <atomic> src/rp2_common/pico_clib_interface/llvm_libc_interface_cpp.cpp:#include <version> src/rp2_common/pico_clib_interface/llvm_libc_interface_cpp.cpp:#include <cstdarg> src/rp2_common/pico_cxx_options/new_delete.cpp:#include <cstdlib> test/kitchen_sink/kitchen_sink_cpp.cpp:#include <vector> tools/pioasm/ada_output.cpp:#include <algorithm> tools/pioasm/ada_output.cpp:#include <iostream> tools/pioasm/ada_output.cpp:#include <sstream> tools/pioasm/c_sdk_output.cpp:#include <algorithm> tools/pioasm/c_sdk_output.cpp:#include <iostream> tools/pioasm/c_sdk_output.cpp:#include <sstream> tools/pioasm/go_output.cpp:#include <algorithm> tools/pioasm/go_output.cpp:#include <iostream> tools/pioasm/go_output.cpp:#include <sstream> tools/pioasm/hex_output.cpp:#include <iostream> tools/pioasm/json_output.cpp:#include <algorithm> tools/pioasm/json_output.cpp:#include <iostream> tools/pioasm/main.cpp:#include <iostream> tools/pioasm/output_format.h:#include <cstdint> tools/pioasm/output_format.h:#include <vector> tools/pioasm/output_format.h:#include <map> tools/pioasm/output_format.h:#include <string> tools/pioasm/output_format.h:#include <memory> tools/pioasm/pio_assembler.cpp:#include <cstdio> tools/pioasm/pio_assembler.cpp:#include <iterator> tools/pioasm/pio_assembler.h:#include <algorithm> tools/pioasm/pio_disassembler.cpp:#include <array> tools/pioasm/pio_disassembler.cpp:#include <sstream> tools/pioasm/pio_disassembler.cpp:#include <iomanip> tools/pioasm/pio_disassembler.h:#include <string> tools/pioasm/pio_disassembler.h:#include <cstdint> tools/pioasm/pio_types.h:#include <cstdint> tools/pioasm/pio_types.h:#include <string> tools/pioasm/pio_types.h:#include <map> tools/pioasm/pio_types.h:#include <set> tools/pioasm/pio_types.h:#include <utility> tools/pioasm/pio_types.h:#include <vector> tools/pioasm/pio_types.h:#include <memory> tools/pioasm/python_output.cpp:#include <array> tools/pioasm/python_output.cpp:#include <algorithm> tools/pioasm/python_output.cpp:#include <sstream> tools/pioasm/python_output.cpp:#include <iomanip> ```
kilograham commented 2026-09-06 20:38:44 -05:00 (Migrated from github.com)

yeah, i mean this is here to make C++ builds compile - I think the better question is why is this breaking the language server - if it defines __cplusplus it ought to provide the header... perhaps you are setting that by mistake?

yeah, i mean this is here to make C++ builds compile - I think the better question is why is this breaking the language server - if it defines `__cplusplus` it ought to provide the header... perhaps you are setting that by mistake?
ancientstraits commented 2026-09-07 00:24:31 -05:00 (Migrated from github.com)

@lurch It only causes an error with clangd. It builds perfectly well.

I think the reason for this discrepancy is that arm-none-eabi-gcc might behave a bit differently from Clang. Maybe it automatically includes C++ headers from a specific place.

Besides that guess, I'm not sure why it breaks the language server.

Also, I think that including assert.h instead of cassert does not change anything (please correct me if I'm wrong!). But hopefully I can figure out how to fix this on the language server side, and what exactly is causing the error.

@lurch It only causes an error with clangd. It builds perfectly well. I think the reason for this discrepancy is that `arm-none-eabi-gcc` might behave a bit differently from Clang. Maybe it automatically includes C++ headers from a specific place. Besides that guess, I'm not sure why it breaks the language server. Also, I think that including `assert.h` instead of `cassert` does not change anything (please correct me if I'm wrong!). But hopefully I can figure out how to fix this on the language server side, and what exactly is causing the error.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#3181
No description provided.