我在 Vim 上使用 YouCompleteMe 插件时遇到问题。
我正在使用 macOS。按照安装指南,我使用--clang-completer
选项安装它。当我编写 C++03 代码时它工作正常。但是当我添加一些 C++11 代码时,插件开始抱怨。
尝试后:YcmDiags
显示如下:
Work/spike/cpp/main.cpp|7 col 12 error| rvalue references are incompatible with C++98
Work/spike/cpp/main.cpp|18 col 10 error| rvalue references are incompatible with C++98
Work/spike/cpp/main.cpp|18 col 5 error| 'auto' type specifier is incompatible with C++98
因此,YouCompleteMe 似乎确实识别了 C++11,但是编译选项有问题。我检查了.ycm_extra_config.py
,其中包含:
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-isystem',
'../BoostParts',
'-isystem',
# This path will only work on OS X, but extra paths that don't exist are not
# harmful
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'./ClangCompleter',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/include',
'-isystem',
'/usr/lib/c++/v1'
]
那么它是来自互联网的默认配置。但我在其中看到-std=c++11
,为什么它不起作用?有什么帮助吗?