c++visual-studio-codeclangd

VSCode cannot detect C++ system files when clangd is enabled


For example, if I include <string>, it will show an error saying 'string' file not found clang(pp_file_not_found): screenshot of the error message

I am building the project into build folder. And use a .clangd file to specify the CompilationDatabase to where compile_commands.json is. This method is successful in my another PC(macOS). For VScode settings about clangd, I specified the clangd.path.

For this PC(Linux Ubuntu), I tried to add "-std=c++17" to 'clangd.fallbackflags'. But it still does not work.

When I use CMake to compile the whole project, it works well. Seems it is a VSCode issue or clangd issue.

Update: I found that if I use #include <9/string> instead of #include <string>, vscode can find the file, is that something about include path? However, I have never made changes to it. So I tried to update the include path by this method Visual Studio Code cannot open source file "iostream". Still does not work.


Solution

  • I solved this problem by adding missing libs:

    sudo apt update
    sudo apt install clang clangd libclang-dev libstdc++-9-dev
    

    Check the installation by:

    echo | clang++ -E -x c++ - -v
    

    Reinstall some libs if there is missing path or other issues:

    sudo apt install --reinstall libstdc++-11-dev libstdc++-9-dev