现在的位置: 首页 > 综合 > 正文

opensuse下利用youcompleteme补全boost库

2018年05月06日 ⁄ 综合 ⁄ 共 2380字 ⁄ 字号 评论关闭

1、安装boost 1.54,这个步骤网上到处都是,我都是默认安装,安装后的boost路径如下:

ywh@linux-ywh:/usr/include/boost> pwd
/usr/include/boost

2、安装好vim、llvm_clang、youcompleteme,我的opensuse12.3默认安装的vim不支持python,只能卸载了从源码安装vim74

      这几个软件非常麻烦,安装化了好长时间,具体可以参考下:

       http://zuyunfei.com/2013/05/16/killer-plugin-of-vim-youcompleteme/

       http://www.cnblogs.com/codemood/p/3142848.html

3、这几个都安装完成后就需要配置youcompleteme了(ycm),具体的配置如下:

       1)在.vimrc中加入以下内容:

         let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py'
         let g:ycm_collect_identifiers_from_tags_files = 1
         let g:ycm_seed_identifiers_with_syntax = 1
         let g:ycm_confirm_extra_conf = 0
         let g:ycm_key_invoke_completion = '<C-/>'
         nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>

        其中ycm_global_ycm_extra_conf非常重要,要让ycm去找搜索路径的。

        2)修改~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py   , 在该文件的

            “flags = [ ” 后面加上两行:

            '-isystem',
             '/usr/include',

            因为我的boost库文件的路径是/usr/include/boost,且其他的c++库文件也在这里/usr/include/下,所以我直接写这个路径。

            如果你的工程在其他位置,可以用-isystem'再次添加其他路径。

       3)启动vim,在vim里添加boost的asio库的头文件:

                        

      4) 按 F5 (上面第一条用F5来让ycm强制编译),用 :messages 看了一下报错了,错误如下:

             Native filetype completion not supported for current file, cannot force recompilation.

             1 /usr/include/boost/asio/impl/error.ipp|34 col 15 error| exception specification of overriding function is more lax than base version                     
             2 /usr/include/boost/asio/impl/error.ipp|66 col 15 error| exception specification of overriding function is more lax than base version
             3 /usr/include/boost/asio/impl/error.ipp|96 col 15 error| exception specification of overriding function is more lax than base version
             4 test.cpp|12 col 7 error| private field 'm_char' is not used
             5 test.cpp|13 col 7 error| private field 'm_char2' is not used

            这个是说.ipp 文件ycm不认识,好吧,咱改一下。

     5) 修改文件 ~/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim   ,找到“let s:forced_syntastic_checker_for”这一样,在下面加上

             .ipp,hpp文件:

             \ 'ipp': 1,
             \ 'hpp': 1,

      6)再次用vim打开文件,然后按F5,然后就有提示了

           

 哈哈,搞定,继续享受ycm吧。

有一点需要补充,变量类型必须要写正确才能有补全,比如对vector的补全,如果你写成

  std::vector<int, int > myvector;

  myvector不会有任何的补全,因为vector没有<int,int>这种类型,修改成std::vector<int > myvector;就可以了

 

4 代码补全没有问题了,但我想在代码间跳来跳去,比如上面的io_service我想跳到他的定义处,在vimrc里加入如下内容:

   nnoremap <F9> :YcmCompleter GoToDefinitionElseDeclaration<CR>

   当光标放到io_service上按 f9就会跳过去,非常爽。再按ctr+o就能条回来,很happy啊。

抱歉!评论已关闭.