clang_complete:iOS 的 Vim 自动补全

发布于 2024-12-11 05:35:07 字数 941 浏览 0 评论 0 原文

所以最近我一直在尝试建立一个基于Vim的iOS工作流程。

我找到了 clang_complete,并在 .vimrc 中设置了 clang 用户选项

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

,如下所述: http://www.zenskg.net/wordpress/?p=199#comment-229

并添加了一些framework/header/lib路径。我不会发布整行内容,因为它太大了。

因此,我在命令行中使用 clang (使用相同的选项)测试了项目中一个文件的编译,它编译得很好,但如果我使用-arch armv6/7 标志。如果我不这样做,它会尝试编译 i386 并抱怨缺少头文件。

到目前为止,一切都很好。现在我只需使用我为 clang 提供的完全相同的选项,以及 .vimrcclang_complete 的用户选项,对吗?

没有。当我这样做并尝试在 Vim 中自动完成一个单词时,它会

 unknown argument: '-arch' 

在 Vim 的 QuickFix 列表中显示。我有点需要这个标志 - 我应该如何进行?

任何有用的想法。我很想让 iOS 代码完成在 Vim 下工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜雨飘雪 2024-12-18 05:35:07

clang_complete 运行 clang -cc1,这会导致编译器前端运行而不是驱动程序。编译器前端不理解 -arch 选项。 clang -cc1 --help 将向您显示可能的选项。您可能应该指定 -triple-target-* 之一。

如果您不确定要使用什么,可以像以前一样手动运行 clang,但以详细模式 (-v) 运行。这样它将打印clang -cc1命令行,您可以在其中找到适当的参数。

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.

初吻给了烟 2024-12-18 05:35:07

默认情况下,clang_complete 使用 clang 二进制文件 /usr/bin/clang,但 Xcode 不是。它使用 clang 库 /Developer/usr/clang-ide/lib/libclang.dylib。它们并不完全相同。如果您要复制 XCode 正在使用的选项,则必须确保 clang_complete 也使用库版本。

.vimrc 文件中类似的内容应该可以做到这一点:

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

当我这样做时,-arch i386 被接受。

(PS - 我在让 clang_complete 进行 iOS 开发时遇到了一些其他问题。您可能想看看这个分支:https://github.com/krisajenkins/clang_complete。我对 clang 太陌生,无法真正知道我在做什么,但它对我有用......)

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

何其悲哀 2024-12-18 05:35:07

使用 5.1 sdk,即使使用 libclang.dylib,我也无法接受 -arch。

经过一番摸索(即,按照建议使用 -v 标志手动运行 xcodebuild 生成的 clang 命令),我最好的设置是:

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'

添加 -cc1 是我唯一做的事情在 Stackoverflow 或其他地方的其他资源中没有看到提到(显然这个标志允许 clang 驱动程序和原始 cc1 标志的混蛋组合通过)。一旦添加了它,它突然就至少可以用于 Cocoa 和 UIKit 完成(尝试输入 [NSString Cx Cu)。

然而,有些东西仍然被轻微破坏。

键入 :copen 完成后(成功或其他)我会看到以下内容:

/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

此外,即使我已将各种 -I 标志添加到我的 .clang_complete< /code> 文件或直接到 clang_user_options 字符串,clang_complete 仅适用于我的项目中的部分标头,但不是全部标头...没有明显的原因为什么可以工作但其他人则不然。 (欢迎提出建议)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文