简体   繁体   English

ycm-generator 传递的 -I 标志缺失导致的 YCM 插件错误如何处理?

[英]How to deal with YCM plugin error caused by lack of -I flag passed by ycm-generator?

Let's say I am using the youcompleteme and ycm generator plugins with vim,假设我在 vim 中使用youcompletemeycm 生成器插件,
and in my CMakeLists.txt file I have something like this: configure_file(src/config.hpp.in config.hpp)在我的CMakeLists.txt文件中我有这样的东西: configure_file(src/config.hpp.in config.hpp)
My project directory structure looks like this:我的项目目录结构如下所示:

> tree
.
├── CMakeLists.txt
└── src
    ├── config.hpp.in
    └── main.cpp

Now, when, in my src/main.cpp file, I have:现在,在我的src/main.cpp文件中,我有:
#include "config.hpp"
The code compiles, because I add代码编译,因为我添加
target_include_directories(target BEFORE PRIVATE "${PROJECT_BINARY_DIR}")
to the CMakeLists.txt file, but because the file included is a file generated from a template,CMakeLists.txt文件,但因为包含的文件是从模板生成的文件,
ycm generator fails to add the build directory (because that is where the config.hpp file ends up) ycm 生成器无法添加构建目录(因为那是 config.hpp 文件结束的地方)
to the flags list, and thus ycm gives me an error that no such file exists.到标志列表,因此 ycm 给我一个错误,指出不存在这样的文件。 I can append this flag manually like so:我可以像这样手动 append 这个标志:

flags = [
     '-x',
     'c++',
     '-I/tmp/tmp36Q3_Q',
     '-Ibuild'
]

But as you can see from the snippet, there already seems to be an -I flag但是正如您从代码片段中看到的那样,似乎已经有一个 -I 标志
appended to the flags list.附加到标志列表。 The name of the directory doesn't really mean anything to me.目录的名称对我来说没有任何意义。
It does make me wonder, if perhaps ycm generator attempted to find my build directory,这确实让我想知道,如果ycm 生成器可能试图找到我的构建目录,
and failed for some reason, like a missing option in cmake?并由于某种原因失败,例如 cmake 中缺少选项?

Does anyone know how to get ycm generator to pass the location有谁知道如何让ycm 生成器传递位置
of the generated file to the include dirs automatically?生成的文件自动包含目录?

To be more precise, I would like to add that I've been generating the.ycm_extra_conf.py file更准确地说,我想补充一点,我一直在生成 .ycm_extra_conf.py 文件
from vim, in the root of the project, with the command:YcmGenerateConfig.来自 vim,在项目的根目录中,使用命令:YcmGenerateConfig。

I have applied a workaround.我已经应用了解决方法。 I modified the output location in the configure_file option to the source directory like so:我将configure_file选项中的 output 位置修改为源目录,如下所示:
configure_file(src/config.hpp.in "${CMAKE_CURRENT_SOURCE_DIR}"/src/config.hpp)
This way, ycm only complains until i "./configure" the project.这样,ycm 只会抱怨,直到我“./configure”项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM