0

I'm using the clangd extension to analysis c/c++ base project in VS code , and this project use many open source projects ,and use the Atom.mk to determine how to build the project. here come the problems: cause the clangd only parse 3 paths relative to the opened cpp file , so some symbols can't be found while I use the "Goto definition" function. cause this definition is completed by other source code . how can I setup the clangd ,make it parse the whole files in directory like C++ intellisense ?

PS: the c++ intellisense is slow in my linux environment, so I discard it. And I google the results ,just told me to use the compile_command.json tell the clang how to build the projects, how is that possible to generate all compile_command.json in all sub_directorys ?

Lex Li
  • 60,503
  • 9
  • 116
  • 147
lianzisong
  • 11
  • 1

1 Answers1

0

As you found, getting clangd to index all the source files in a project is accomplished by having a compile_commands.json file with an entry for each source file in the project.

The compile_commands.json file is usually generated at build time. The exact mechanism will vary depending on your project's build system (see https://clangd.llvm.org/installation#project-setup for some examples), but a common way is to use Bear to wrap your build command, e.g. if your build command is make, you would run bear -- make and bear will record the compiler commands invoked during the build and generate the compile_commands.json based on them.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • thanks reply. Cause my project is a embeded software , the whole project is assemble by a 3rd building system. And I try to pass the commands to the Bear , the first time I got the empty compile_commands.json file ,then I clean the project , Now I'm waiting for the result . – lianzisong Mar 14 '23 at 07:14
  • I got the result , and the compile_command.json was generated successfully , But it seems that the cland server still can't locate some symbols , so the problems still back to how to parsing whole folders like gtags/c++ intellisense by clangd? – lianzisong Mar 14 '23 at 07:29
  • @lianzisong for a cross-compilation setup, you probably need to use `--query-driver`, please see https://clangd.llvm.org/troubleshooting#cant-find-standard-library-headers-map-stdioh-etc (particularly the last paragraph), and also `clangd --help` for more details about the `--query-driver` option – HighCommander4 Mar 14 '23 at 07:46