clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
639 stars 113 forks source link

macOS C++ CMake project cannot find any C++ header file so clangd fails. #164

Open imikejackson opened 3 years ago

imikejackson commented 3 years ago

Please describe the problem. For hints on what information is helpful, see: https://clangd.llvm.org/troubleshooting.html

If you can, provide a minimal chunk of code that shows the problem (either inline, or attach it if larger).

C++ file where #Include or really any standard C++ file is included. None of the includes will resolve.

Logs Please attach the clangd log from the "Output" window if you can. If possible, run with --log=verbose - note that the logs will include the contents of open files! clangd.log

System information Clangd version : 11.0.0 clangd extension version: 0.1.11 Operating system:macOS 10.15

findNextStep commented 3 years ago

try add some code in ~/Library/Preferences/clangd/config.yaml

if you install llvm and xcode

CompileFlags:
  Add: [
      -isystem/usr/local/opt/llvm/include/c++/v1,
      -isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
      ]

if you only install llvm

CompileFlags:
  Add: [
      -isystem/usr/local/opt/llvm/include/c++/v1,
      -L/usr/local/opt/llvm/lib/clang/11.1.0
      ]

it work for me

hijkzzz commented 3 years ago

me too

findNextStep commented 3 years ago

I found add qurey driver help to make it work

  "clangd.arguments": [
+    "--query-driver=/usr/bin/clang++",
  ],
mrexodia commented 2 years ago

I found add qurey driver help to make it work

  "clangd.arguments": [
+    "--query-driver=/usr/bin/clang++",
  ],

I think this should be the default setting on macos, it was a pain to find this.

HighCommander4 commented 2 years ago

Some discussion about that in https://github.com/clangd/clangd/issues/539

dmorn commented 1 year ago

Hey, if someone ends on this issue like me I found this snippet from the installation page very useful! It helps generating a compile_commands.json that clangd will use to find your project's deps 😉

If your project builds with CMake, it can generate this file. You should enable it with:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
compile_commands.json will be written to your build directory. If your build directory is $SRC or $SRC/build, clangd will find it. Otherwise, symlink or copy it to $SRC, the root of your source tree.

ln -s ~/myproject-build/compile_commands.json ~/myproject/