ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2021-06-27 17:03:49  阅读:252  来源: 互联网

标签:.. compilation 配置 c++ isystem usr YCM 简单 include


可能是最简单的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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有