Using clang_complete with OS X frameworks

巧了我就是萌 提交于 2019-12-04 08:29:17
Sam

See clang_complete: Vim autocompletion for iOS for a helpful answer. Apparently clang_complete uses the -cc1 option which doesn't support the -framework argument.

I was able to use -triple and -target options as replacements for the -arch argument I needed, maybe one of the -cc1 args can replace -framework?

To reproduce your error, you can do

:! clang -cc1 % -framework CoreServices

So I think the question now becomes "How can I pass frameworks to clang -cc1?".

EDIT: By running

clang++ -v -framework CoreServices ./test.cpp 

You can get the output of clang -cc1

Mine was

-triple x86_64-apple-macosx10.6.7 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 123.2 -v -resource-dir /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/../lib/clang/2.1 -fdeprecated-macro -ferror-limit 19 -fmessage-length 179 -stack-protector 1 -fblocks -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/w2/w26NavGvGauuJwhTtEeQ9++++TI/-Tmp-/cc-GbJXd6.o -x c++ ./test.cpp

I removed the -o argument, and the input file, from the end and added it to the user options in .vimrc but code completion still doesn't work correctly.. Hmm

In case anyone also still has this problem (I'm having it with the spacemacs extensions to company-clang, but I expect the issue is the same)...

The clang -framework argument is apparently passed to the linker, while clang -cc1 is concerned exclusively with compiling (so it doesn't know about or support linker options; it does accept a linker-option=<option> argument, apparently, which worked for me in my shell, but was unrecognized when added to the .clang_complete file). A framework is basically just a bunch of nested collections of headers, though, so you can just include all the headers you need in the framework manually with -I and it will work.

Example for Qt5:

Instead of...

-F/usr/local/opt/qt5/lib
-framework QtCore

Use...

-I/usr/local/opt/qt5/lib/QtCore.framework/Versions/Current/Headers

I guess you may have to do some introspection of the headers in your particular framework to figure out exactly which directories to include. Could be a lot of them. Not very pretty, but it works (in my case, at least).

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