5

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?

Peeter Joot
  • 7,848
  • 7
  • 48
  • 82
irh
  • 668
  • 5
  • 11
  • VIM try to search clang_complete from you cwd no? Then if you're not in /tmp/ your file must not be in /tmp/ ! – Jaffa Oct 08 '11 at 21:33
  • cwd is /tmp/ - I know the .clang_complete file is being read because of the 'unknown argument' error only appearing when I add the `-framework` option to .clang_complete. – irh Oct 09 '11 at 12:08
  • You mean to call clang_complete using :!clang++ ? But this only call the compiler! Is your clang_complete this plugin : http://www.vim.org/scripts/script.php?script_id=3302 ? – Jaffa Oct 09 '11 at 18:22
  • I know that calls the compiler :) I've got clang_complete working fine, just not with frameworks. It is that plugin although I'm using the latest version from https://github.com/Rip-Rip/clang_complete – irh Oct 09 '11 at 20:46
  • I am having the same issue with the -arch flag. I can compile my project with clang from the command line, but clang_complete complains of unknown argument:'-arch'. I had a look through the source and although I'm not familiar with python, all the useroptions arguments seem to get cleanly passed through to libclang.dylib (to the function clang_parseTranslationUnit). That's as far as I've got now- I posted an issue on the project page. Will keep you updated if I make progress. – Sam Oct 21 '11 at 13:06
  • If anybody knows how to test whether libclang.dylib supports certain arguments, that could rule it out (or not). – Sam Oct 21 '11 at 13:45

2 Answers2

0

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

Jason Nance
  • 93
  • 1
  • 2
  • 5
0

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

Community
  • 1
  • 1
Sam
  • 3,659
  • 3
  • 36
  • 49