4

I have installed the plugin clang_complete. I put these settings in my .vimrc:

   let g:clang_use_library      = 1
   let g:clang_auto_select      = 0
   let g:clang_complete_auto    = 1
   let g:clang_complete_copen   = 1
   let g:clang_complete_macros  = 1
   let g:clang_complete_patters = 1
   set completeopt=menu,longest

   let g:clang_library_path = '/usr/lib/clang'
   "let g:clang_library_path = '/usr/lib/llvm-2.9'

   let g:clang_auto_user_options = "-I/usr/include/c++/4.6, .clang_complete"
   let g:clang_snippets = 1
   let g:clang_snippets_engine = 'clang_complete'

Every time when I open the .cpp file I have got the following error message:

Error detected while processing function <SNR>15_ClangCompleteInit..LoadUserOptions:
line   20:
E121: Undefined variable: getopts#
Loading libclang failed, falling back to clang executable.  Are you sure '/usr/bin/clang' contains libclang?

vim is compiled with the python feature. So vim --version is gets:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 28 2012 13:50:08)
Included patches: 1-154

 ... +python -python3 ...  

Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_ATHENA     -Wall -g -O2 -D_FORTIFY_SOURCE=1     -I/usr/include/tcl8.5  -D_REENTRANT=1  -D_THREAD_SAFE=1  -D_LARGEFILE64_SOURCE=1  
Linking: gcc   -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic  -Wl,-E  -Wl,-Bsymbolic-functions -Wl,--as-needed -o vim -lXaw -lXmu -lXext -lXt -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -ldl -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.1  -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.12/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  -L/usr/lib -ltcl8.5 -ldl -lpthread -lieee -lm -lruby1.8 -lpthread -lrt -ldl -lcrypt -lm   

Can anybody help to resolve the problem?

4

1 回答 1

2

你这里有两个问题。

  1. 您提供的值g:clang_auto_user_options无效。clang_complete 文档中提到的“路径”并不意味着路径应该写在选项字符串中;它指的是使用 Vim 的内置'path'选项来提供-I标志列表。

    改用set g:clang_user_options = "-I/usr/include/c++/4.6"它,它会直接传递给 clang。

    旁白:出现getopts#错误是因为 clang_complete 尝试将您的-I...字符串解释为选项源函数名称的一部分。({anything}文档中的子句。)-ingetopts#-I/usr/include/c++/4.6#getops()不是有效的 Vimscript 函数字符,因此它在那里被截断。

  2. clang_complete 期望g:clang_library_path您指定的目录包含libclang.dyliborlibclang.so直接在其中(例如/usr/lib/clang/libclang.so,在您的情况下)。

    并非所有 clang 发行版都提供 libclang 共享库,因此您可能需要自己编译它。

于 2013-06-10T05:24:54.367 回答