If I save the following to /tmp/test.cpp:
#include <CoreServices/CoreServices.h>
#include <iostream>
int main() {
CFStringRef my_string = CFSTR("hello, world!");
std::cout << CFStringGetLength(my_string) << '\n';
}
I can compile this correctly with !clang++ -framework CoreServices %
, however clang_complete can't complete anything from CoreServices.
The docs say I should place compiler options in a .clang_complete file (in this case I'm using /tmp/.clang_complete), however everything I've tried so far results in test.cpp|| unknown argument: '-framework'
appearing in the quick fix window.
What's the correct way of getting clang_complete to deal with frameworks correctly?
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).
来源:https://stackoverflow.com/questions/7697831/using-clang-complete-with-os-x-frameworks