YouCompleteMe builds an index of C/C++ CMmake projects

introduce

If YouCompleteMe is installed and configured (this site has process records,click here to view), you can use a single file to detect the effect of code hints. However, when S&E opened his C/C++ project, he found that functions such as code hints and jumps could not be used normally. After consulting the documentation, S&E found that the index database related to YouCompleteMe was not established, and the related compilation options were incorrect, so the clangd used by YouCompleteMe could not link multiple source files.

method

If you use CMake to build the project, you can add it to CMakeList.txt

set( CMAKE_EXPORT_COMPILE_COMMANDS ON )

Or add it after the command line cmake-DCMAKE_EXPORT_COMPILE_COMMANDS=ONalso

principle

YouCompleteMe reads the compilation database (usually named compile_commands.json) generated by the build system CMake, so that you can complete the indexing of project files. Instead, the compilation database contains compiler invocations for each compilation unit in the project. YouCompleteMe will look for compile_commands.json in the directory where the open file is located, and if not found it will recursively look up this file. If it finds compile_commands.json before it finds .ycm_extra_conf.py, it stops searching and then lets clangd handle take over and process the flags contained in that file.

After completing the above operations, the related functions of YouCompleteMe can be used normally.

zh_CNZH-CN