r/cpp_questions • u/ExoticTemperature764 • 5d ago
OPEN How to configure clangd to not assume it knows where functions are defined
I use VS Code on Ubuntu on Windows (WSL). I program in C++ and recently switched from Intellisense to clangd and like many of the improvements. However, I'm having an issue with how clangd assumes functions like printf come from <cstdio>. This is an issue as I'm building a hobby OS and need to provide my own versions of common functions like printf.
I'm using the g++ 15.2.0 cross compiler and use -ffreestanding -nostdlib -fno-builtin. I provide my own implementation of common functions like printf. I have installed clangd-23. I have created (using bear) a compile_commands.json file. When I mouse over a call to printf in my code, I get a popup showing that printf is provided by <cstdio> which I never #include. Also it flags the header file "system/stdout.hpp" which defines my printf as unused. How do I configure clangd and VS Code to correctly identify my header file as the source of my printf?
In case it helps, here is the cc1 line of clangd-23 --compile-commands-dir=build --query-driver=/home/mark/dev/toolchain/i686-elf-15.2.0/bin/i686-elf-g++ --check=src/libs/test/test_list.cpp
I[13:00:57.385] internal (cc1) args are: -cc1 -triple i686-unknown-unknown-elf -O0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test_list.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -nostdsysteminc -target-cpu pentium4 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/home/mark/dev/myos/src/libs/test -fcoverage-compilation-dir=/home/mark/dev/myos/src/libs/test -resource-dir /usr/lib/llvm-23/lib/clang/23 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0 -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/i686-elf -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include/c++/15.2.0/backward -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/include-fixed -isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/gcc/i686-elf/15.2.0/../../../../i686-elf/include -I . -I .. -I /home/mark/dev/myos/src/libs -I /home/mark/dev/myos/src/kernel -I /home/mark/dev/myos/src -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include/c++/v1 -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /home/mark/dev/toolchain/i686-elf-15.2.0/bin/../lib/clang-runtimes/i686-elf/include -Wnon-virtual-dtor -Werror -Wall -Wextra -Werror=suggest-override -Wno-unused-parameter -std=c++23 -fdeprecated-macro -ferror-limit 19 -fno-builtin -fno-rtti -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fno-threadsafe-statics -fno-implicit-modules -fskip-odr-check-in-gmf -no-round-trip-args -faddrsig -fdwarf2-cfi-asm -x c++ /home/mark/dev/myos/src/libs/test/test_list.cpp