1

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.

10
  • did you follow the project setup instructions for the clangd extension? (I.e. put a compile commands database file in the workspace root? see also stackoverflow.com/q/76214615/11107541) Commented Sep 7, 2023 at 7:08
  • Yes, I use CMake and use set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to set. Also use .clangd file to specify the position of compile_commands.json. Also add "-std=c++17" to 'clangd.fallbackflags'. Still does not work. Commented Sep 7, 2023 at 7:28
  • okay, but is your build directory set to the source directory, then? (in-source build)? Commented Sep 7, 2023 at 7:29
  • Do you mean {my_project_path}/build? I did so. Commented Sep 7, 2023 at 7:33
  • if you're building to a subdirectory of the source directory, then that is not an in-source build, and you need to follow the instructions in the post which I linked you to. Commented Sep 7, 2023 at 7:34

2 Answers 2

2

You might be running into a known issue affecting Ubuntu 22.04: https://github.com/clangd/clangd/issues/1394.

You can read about the available workarounds in this comment, but this simplest one is to install g++-12.


If that's not the issue, my next suggestion is to read these parts of the clangd docs:

and try --query-driver in particular.


If you're still not having any luck, please share clangd logs for further diagnosis.

Sign up to request clarification or add additional context in comments.

Comments

0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.