clang_complete: Vim autocompletion for iOS

China☆狼群 提交于 2019-12-09 13:05:28

问题


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.


回答1:


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.




回答2:


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...)




回答3:


Using the 5.1 sdk I wasn't able to get -arch accepted even when using libclang.dylib.

After some futzing (namely, manually running the clang commands produced by xcodebuild with the -v flag as suggested), my best setup was:

let g:clang_complete_auto = 1

"not strictly necessary
set omnifunc=ClangComplete

let g:clang_user_options='clang -cc1 -triple i386-apple-macosx10.6.7 -target-cpu yonah -target-linker-version 128.2 -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/3.1 -fblocks -x objective-c -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -D __IPHONE_OS_VERSION_MIN_REQUIRED=50100 || exit 0'

adding -cc1 is the only thing I don't see mentioned in other resources on Stackoverflow or elsewhere (apparently this flag allows the bastardized combination of clang driver and raw cc1 flags to go through). Once this was added it suddenly just worked at least for Cocoa and UIKit completion (try typing [NSString C-x C-u).

However, something's still mildly busted.

Typing :copen I see this after a completion (successful or otherwise):

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h|654 col 48 error| expected ';' after top level declarator

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFUtilities.h|14 col 39 error| expected function body after function declarator
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h|60 col 32 info| expanded from macro 'CF_AVAILABLE_IOS'
/usr/include/Availability.h|145 col 53 info| expanded from macro '__OSX_AVAILABLE_STARTING'
<scratch space>|25 col 1 info| expanded from macro '__AVAILABILITY_INTERNAL'
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h|92 col 10 error| 'CoreFoundation/CFUserNotification.h' file not found

Also, even though I've added various -I flags to either my .clang_complete file or directly to the clang_user_options string, clang_complete only works with some but not all of the headers in my project... with no apparent reason why one works but not others. (Suggestions welcome).



来源:https://stackoverflow.com/questions/7840791/clang-complete-vim-autocompletion-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!