Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang_complete: Vim autocompletion for iOS

So recently I have been trying to set up a Vim-based iOS workflow.

I found clang_complete, and have set the clang user options in my .vimrc like so

let g:clang_user_options='-fblocks -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300'

as described here: http://www.zenskg.net/wordpress/?p=199#comment-229

and added a few framework/header/lib paths. I'm not going to post the whole line because it is huge.

So I tested the compilation of one of the files in my project using clang from the command line (using the same options), and it compiles fine, but only if I use the -arch armv6/7 flag. If I don't it tries to compile for i386 and complains of missing header files.

So far so good. Now I just use the exact same options I gave to clang, to clang_complete's user options in my .vimrc right?

Nope. When I do that and try to autocomplete a word in Vim, it says

 unknown argument: '-arch' 

in the QuickFix list of Vim. I kinda need this flag- how should I proceed?

Any ideas useful. I would love to get iOS code completion working under Vim.

like image 435
Sam Avatar asked Oct 20 '11 18:10

Sam


2 Answers

clang_complete runs clang -cc1, which causes the compiler front-end to run and not the driver. The compiler front-end doesn't understand the -arch option. clang -cc1 --help will show you the possible options. You should probably specify -triple or one of -target-*.

If you're not sure what to use, you can run clang manually as you did, but in verbose mode (-v). This way it will print the clang -cc1 command line, where you can find the appropriate arguments.

like image 105
Itay Perl Avatar answered Sep 23 '22 21:09

Itay Perl


By default, clang_complete is using the clang binary /usr/bin/clang, but Xcode isn't. It's using the clang library /Developer/usr/clang-ide/lib/libclang.dylib. They're not quite the same. If you're copying the options that XCode is using, you'll have to make sure clang_complete uses the library version too.

Something like this in your .vimrc file should do it:

filetype on
autocmd FileType objc let g:clang_use_library=1
autocmd FileType objc let g:clang_library_path='/Developer/usr/clang-ide/lib'

When I do that, -arch i386 is accepted.

(PS - I had a couple of other problems getting clang_complete to work for iOS development. You might want to check out this fork: https://github.com/krisajenkins/clang_complete. I'm too new to clang to really know what I'm doing, but it's working for me...)

like image 22
Kris Jenkins Avatar answered Sep 21 '22 21:09

Kris Jenkins