3. youcompleteme编译安装

参考网址: https://github.com/ycm-core/YouCompleteMe#linux-64-bit

建议不要用这个博客的方法: https://github.com/yangyangwithgnu/use_vim_as_ide

  1. 安装插件管理器vundle

    git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    # 在 ~/.vimrc 增加相关配置信息 " vundle 环境设置
    filetype off
    set rtp+=~/.vim/bundle/Vundle.vim
    " vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间
    call vundle#begin()
    Plugin 'VundleVim/Vundle.vim'
    Plugin 'ycm-core/YouCompleteMe' " 插件列表结束
    call vundle#end()
    filetype plugin indent on
  2. 打开vim, 输入:PluginInstall, 下载YouCompleteMe

  3. 安装

    # 依赖项
    sudo apt install build-essential cmake python3-dev
    cd ~/.vim/bundle/YouCompleteMe
    # 如果要选择其他语言支持可以选, 参考网址里有
    python install.py --clang-completer
  4. 编辑文件在工程项目目录中新建.ycm_extra_conf.py,我们只需要改flags中头文件的目录即可,内容如下(此内容参考https://github.com/yangyangwithgnu/use_vim_as_ide):

    import os
    import ycm_core
    flags = [
    '-std=c++11',
    '-O0',
    '-Werror',
    '-Weverything',
    '-Wno-documentation',
    '-Wno-deprecated-declarations',
    '-Wno-disabled-macro-expansion',
    '-Wno-float-equal',
    '-Wno-c++98-compat',
    '-Wno-c++98-compat-pedantic',
    '-Wno-global-constructors',
    '-Wno-exit-time-destructors',
    '-Wno-missing-prototypes',
    '-Wno-padded',
    '-Wno-old-style-cast',
    '-Wno-weak-vtables',
    '-x',
    'c++',
    '-I',
    '.',
    '-isystem',
    '/usr/local/include/c++/v1/',
    '-isystem',
    '/usr/include/',
    '-isystem',
    '/usr/',
    '-isystem',
    '/usr/include/x86_64-linux-gnu/',
    ]
    compilation_database_folder = ''
    if 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 MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
    if not working_directory:
    return list( flags )
    new_flags = []
    make_next_absolute = False
    path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
    for flag in flags:
    new_flag = flag
    if make_next_absolute:
    make_next_absolute = False
    if not flag.startswith( '/' ):
    new_flag = os.path.join( working_directory, flag )
    for path_flag in path_flags:
    if flag == path_flag:
    make_next_absolute = True
    break
    if flag.startswith( path_flag ):
    path = flag[ len( path_flag ): ]
    new_flag = path_flag + os.path.join( working_directory, path )
    break
    if new_flag:
    new_flags.append( new_flag )
    return new_flags
    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 database:
    compilation_info = GetCompilationInfoForFile( filename )
    if not compilation_info:
    return None
    final_flags = MakeRelativePathsInFlagsAbsolute(
    compilation_info.compiler_flags_,
    compilation_info.compiler_working_dir_ )
    else:
    relative_to = DirectoryOfThisScript()
    final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
    return {
    'flags': final_flags,
    'do_cache': True
    }

    这个在 https://github.com/whuwzp/vim_config 中有保存

注意:

  1. .ycm_extra_conf.py中的头文件添加方法: 我安装clang是用默认的路径/usr/local,所以增加了'-isystem', '/usr/local/include/c++/v1/'

    • '-isystem','/usr/include/': 这个是系统头文件
    • '-isystem','/usr/': 这也是系统的
    • '-isystem','/usr/include/x86_64-linux-gnu/':这个是linux的
  2. 如果发现某个函数不能补全或者报错的解决方法

    先看看函数所属的头文件,然后在百度或者直接去/usr/include,等位置去找找, 然后添加到.ycm_extra_conf.py中, 例如sys/socket.h没有自动补全,百度发现在/usr/include/x86_64-linux-gnu/中, 然后在添加'-isystem','/usr/include/x86_64-linux-gnu/'即可

  3. 强烈建议不要复制头文件到/usr/include

    这样图一时方便,但全都混乱了,就用上一步的方法最好,也便于自己理解各头文件的位置

  4. ycm server shutdown的解决方法

    需要进入~/.vim/bundle/youcompleteme目录下,install,具体如下:

    # 如果不执行这一步,下一步就报错
    git submodule update --init --recursive
    # 然后install
    sudo ./install.sh --clang-completer
    # 如果上一步报错缺少regex或者cregex,那就是git submodule update --init --recursive没有完全下载,那就去目录下找,例如我的是regex,到youcompleteme的github下找到了thrid/ycmd/third/regex,然后发现子项目的地址https://github.com/ycm-core/regex.git,然后自己git clone下来,手动拷贝到那个目录就好,例如git clone https://github.com/ycm-core/regex.git
  5. 不能补全另一个文件中自定义的类

    YCM 只在如下两种场景下触发语义补全:一是补全标识符所在文件必须在 buffer 中(即,文件已打开);一是在对象后键入 .、指针后键入 ->、名字空间后键入 ::。

    所以必须打开那个文件才行.

  6. 如果没有boost

    那就自己下载安装boost

    以下参照: https://www.cnblogs.com/smallredness/p/9245127.html

    解压到一个目录
    tar -zxvf boost_1_66_0.tar.gz
    1、正常编译:
    进入boost_1_66_0目录中
    cd boost_1_66_0
    ./bootstrap.sh --with-libraries=all --with-toolset=gcc
    --with-liraries:需要编译的库
    --with-toolset:编译时使用的编译器
    安装boost库
    ./b2 install --prefix=/usr
  7. 编译警告可以参见:https://blog.csdn.net/qq_17308321/article/details/79979514

Linux c++ vim环境搭建系列(3)——Ubuntu18.04.4编译安装youcompleteme的更多相关文章

  1. Linux c++ vim环境搭建系列(1)——Ubuntu18.04.4编译安装vim8.2

    1. vim源码编译安装 参考网址: https://github.com/ycm-core/YouCompleteMe/wiki/Building-Vim-from-source 安装各类依赖库 s ...

  2. Linux c++ vim环境搭建系列(0)——简介

    vim 学习 简介: 源码编译使用vim及其插件. 内容包含: vim的编译安装, llvm clang的编译安装, 插件youcompleteme的编译安装使用, 以及vim其他插件的使用. 搭建环 ...

  3. Linux c++ vim环境搭建系列(2)——Ubuntu18.04.4编译安装llvm clang

    2. 源码编译安装llvm clang 参考网址: https://llvhttps

  4. Linux c++ vim环境搭建系列(5)——vim使用

    5. 使用 5.1 快捷键及设置 5.1.1 光标移动 w : 正向移动到相邻单词的首字符 b : 逆向移动到相邻单词的首字符 e : 正向移动到相邻单词的尾字符 ge : 逆向移动到相邻单词的尾字符 ...

  5. Linux c++ vim环境搭建系列(4)——vim插件安装配置使用

    4. 插件 主要是c++相关的. ~/.vimrc文件在GitHub上有:https://github.com/whuwzp/vim_config 以下内容参考: https://github.com ...

  6. Linux c++ vim环境搭建系列(6)——CMakeLists.txt多文档多目录组织方法和编写示例

    CMakeLists.txt学习 1. 概要 主要是关于cmakelists.txt的编写模板,和多文档多目录的组织方法详解, 涉及第三方库的添加使用方法. 这里主要介绍cmakelists.txt的 ...

  7. 环境搭建系列-系统安装之centos 6.5安装与配置

    按照国际惯例,系列目录先奉上: 系列一:系统安装之centos 6.5安装与配置 系列二:准备工作之Java环境安装 系列三:数据为先之MySQL读写集群搭建 系列四:谈分布式之RabbitMQ集群搭 ...

  8. Ubuntu18.04下编译安装Guitarix 0.37.3

    准备工作 源文件下载 https://sourceforge.net/projects/guitarix/files/guitarix/ 安装依赖. 参考 https://sourceforge.ne ...

  9. Ubuntu环境搭建系列—JavaEE篇

    恩,其实我是一时兴起,所以就写了目前这几篇环境的博文,希望能给自己做一个笔记,同时也能够给一些新手带来一些帮助,不会在配置方面那么迷茫.本篇文章主要就是针对Java web开发进行环境搭建. 一.To ...

随机推荐

  1. java-FileUtils(复制文件夹、复制文件、字符串直接写入文件中)(新手)

    实例: lx1: import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; pu ...

  2. 在Linux环境安装redis步骤,且设置开机自动启动redis

    最近在linux环境安装了redis学习,目前已经安装成功且设置开机即启动状态,我把步骤流程记录了下来,分享给需要的小伙伴. 1.我在/usr/local/localsoftware/目录下创建了一个 ...

  3. Windows10专业版+Microsoft office2016专业增强版免费无毒官方正版装机教程(简)

    win10: 1.官网制作系统盘(具体见官网提示) 2.备份C盘 3.重启,主板调到USB优先(重启后疯狂按F12或del,具体看主板型号) 4.安装(这个看造化) 5.激活 slmgr /ipk N ...

  4. iOS开发如何面对疫情过后的面试高峰期 !

    2020年本应该是一个 "爱你.爱你"的年份!却因为 黑天鹅 给我们带来非常大的影响! 一.2020年iOS招聘数据分析 这里是 2020年3月份BOSS直聘 北京iOS招聘前几页 ...

  5. 云CRM和本地CRM哪个更好

    现在CRM系统按照服务器部署方式的不同分为本地CRM和云CRM两种,本地CRM需要在企业内部部署服务器,而云CRM的服务器则是安装在云服务器上面,很多企业可能不知道应该选择云CRM还是本地CRM.下面 ...

  6. SQL的分类使用(增删改查)

    1.SQL的分类使用(*代表重点的程度)    DDL ** (Data Definition Language)数据库定义语言        用来定义数据库对象: 库 表 列 等    DCL (D ...

  7. IntegerCache缓存占用堆、栈、常量池的问题,自动拆装箱的基本概念,Integer==int时的问题说明

    原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 先普及一个基本概念:Java中基本数据类型的装箱和拆箱操作 自动装箱 在JDK5以后,我们 ...

  8. hdu3336 Counting the string kmp的next数组的应用

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/3336/ 题意就是要求一个字符串的所有前缀在字符串中出现的次数之和,我们容易想到kmp中的next数组,next[ ...

  9. Node/Python 工具搭建cmder和nrm

    一.安装cmder cmder是windows下的一款终端工具,支持很多linux命令,用起来还是很爽的. 1.安装 http://cmder.net/ 直接在官网下载,解压即可. 2.cmder配置 ...

  10. JVM 常见参数配置

    -XX:+PrintGC  每次触发GC的时候打印相关日志 -XX:+PrintGCDetails 每次触发GC的时候更详细的相关日志 -XX:+UseSerialGC 串行回收 -Xms 堆初始值( ...