英文:
nvim + clangd | compile_commands.json with MetaProject
问题
我正在为我的工作项目设置 nvim,该项目是使用空的 MetaProject 构建的,该项目构建了多个子项目,我遇到了 clangd 的问题。它无法识别自定义标头或类。我知道 clang 需要 compile_commands.json
才能知道要查找的位置,但当我使用 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
构建项目时,该文件不会在根目录生成,而会在多个子项目中生成多个文件。
我找到了我的项目的 compile_commands.json
,但我该如何告诉 clangd 使用构建目录中的此自定义路径?
假设路径是${workspaceFolder}/MetaProject/build/1/2/3/compile_commands.json
。
我是 nvim 的新手,我使用 NvChad 并额外安装了 clangd。
我想友好地请教您帮助,因为我不知道如何继续工作,没有 clangd 的话会很痛苦。
干杯!
英文:
I am setting up nvim for my work project which is built using empty MetaProject that builds multiple sub-projects and I have issue with clangd. It doesn't recognize custom headers or classes. I know that compile_commands.json
is needed for clang in order to know where to look, but when I build project with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
I won't have that file generated in root directory, but multiple files in multiple sub-projects.
I found compile_commands.json
for my project but how can I can tell clangd this custom path in build directory?
Let's say that path is ${workspaceFolder}/MetaProject/build/1/2/3/compile_commands.json
I am new to nvim and i use NvChad + additionally installed clangd.
I would like to kindly ask you for help because I don't know how to proceed and working without clangd is a pain in the ***.
Cheers!
答案1
得分: 3
Sure, here's the translated content:
如何告诉clangd在构建目录中使用自定义路径?
来自https://clangd.llvm.org/config#compilationdatabase
.clangd
CompileFlags:
CompilationDatabase:路径由于我只在Linux上工作,我发现只需在根CMakeLists.txt中创建一个符号链接,将项目目录链接到构建目录会更加简单。像这样:
如果(THE_PROJECT_DEV) # 用于检查项目开发人员的标志
执行过程(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
)
endif()
英文:
> how can I can tell clangd this custom path in build directory?
From https://clangd.llvm.org/config#compilationdatabase
# .clangd
CompileFlags:
CompilationDatabase: the path
As I work only on Linux, I found it is extremely simpler to just create a symlink from project dir to the build directory. Like so in root CMakeLists.txt
if (THE_PROJECT_DEV) # a flag to check for project developers
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
)
endif()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论