其他分享
首页 > 其他分享> > 可能是最简单的YCM配置文~

可能是最简单的YCM配置文~

作者:互联网

可能是最简单的YCM配置文~

超级简便的安装~

YouCompleteMe安装前先检查自己的vim版本、python版本与cmake版本

YouCompleteMe需要: vim 8.1+;cmake3.15+;python3.5+;

cmake安装可参考本人的另一篇博客: Ubuntu下的cmake自选版本安装

一切就绪,准备安装。

网上有各种各样的相关安装教程,但是笔者源码安装尝试多次失败,总是最后执行py文件提示缺库,按照提示补库最后又总是Failed to build,直到发现以下简便方式:

执行命令:

$sudo apt-get install vim-youcompleteme

等待安装完成,配置一下,执行命令:

$sudo vim-addon-manager install youcompleteme

如此YouCompleteMe插件便安装好了非常简单是不是

.ycm_extra_conf.py 配置

首先附上我自己的配置文件:


# Copyright (C) 2014 Google Inc.
#
# This file is part of ycmd.
#
# ycmd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ycmd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ycmd.  If not, see <http://www.gnu.org/licenses/>.
 
import os
import ycm_core
 
# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-fexceptions',
'-DNDEBUG',
# 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',
'/usr/bin/..b/gcc/arm-linux-gnueabihf/8/../../../../include/c++/8',
'-isystem',
'/usr/bin/..b/gcc/arm-linux-gnueabihf/8/../../../../include/arm-linux-gnueabihf/c++/8',
'-isystem',
'/usr/bin/..b/gcc/arm-linux-gnueabihf/8/../../../../include/c++/8/backward',
'-isystem',
'/usr/include/clang/7.0.1/include',
'-isystem',
'/usr/local/include',
'-isystem',
'/usr/include/arm-linux-gnueabihf',
'-isystem',
'/usr/include'
]
 
 
compilation_database_folder = ''
 
if os.path.exists( compilation_database_folder ):
  database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
  database = None
 
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
 
def DirectoryOfThisScript():
  return os.path.dirname( os.path.abspath( __file__ ) )
 
 
def IsHeaderFile( filename ):
  extension = os.path.splitext( filename )[ 1 ]
  return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
 
 
def GetCompilationInfoForFile( filename ):
  if IsHeaderFile( filename ):
    basename = os.path.splitext( filename )[ 0 ]
    for extension in SOURCE_EXTENSIONS:
      replacement_file = basename + extension
      if os.path.exists( replacement_file ):
        compilation_info = database.GetCompilationInfoForFile(
          replacement_file )
        if compilation_info.compiler_flags_:
          return compilation_info
    return None
  return database.GetCompilationInfoForFile( filename )
 
 
def FlagsForFile( filename, **kwargs ):
  if not database:
    return {
      'flags': flags,
      'include_paths_relative_to_dir': DirectoryOfThisScript()
    }
 
  compilation_info = GetCompilationInfoForFile( filename )
  if not compilation_info:
    return None
 
  return {
    'flags': list( compilation_info.compiler_flags_ ),
    'include_paths_relative_to_dir': compilation_info.compiler_working_dir_
  }

重点是flags数组里的这段:

'-isystem',
'/usr/bin/..b/gcc/arm-linux-gnueabihf/8/../../../../include/c++/8',
'-isystem',
'/usr/bin/..b/gcc/arm-linux-gnueabihf/8/../../../../include/arm-linux-gnueabihf/c++/8',
'-isystem',
'/usr/bin/..b/gcc/arm-linux-gnueabihf/8/../../../../include/c++/8/backward',
'-isystem',
'/usr/include/clang/7.0.1/include',
'-isystem',
'/usr/local/include',
'-isystem',
'/usr/include/arm-linux-gnueabihf',
'-isystem',
'/usr/include'

千万不要照抄我的路径
命令行输入

$echo | clang -v -E -x c++ -

然后将图中圈中部分的路径依次放在'-isystem'后面

image

到此结束(maybe)有疑问欢迎评论~

标签:..,compilation,配置,c++,isystem,usr,YCM,简单,include
来源: https://www.cnblogs.com/stagonie/p/14940930.html