xavierd / clang_complete

Vim plugin that use clang for completing C/C++ code.
http://www.vim.org/scripts/script.php?script_id=3302
1.96k stars 308 forks source link

clang_complete doesn't support -arch argument #94

Closed darkFunction closed 12 years ago

darkFunction commented 13 years ago

I'm trying to use Vim for autocompleting iOS code. I can compile my project with clang using the -S command to do the code generation and it works fine. However I need to specify the '-arch -386' or '-arch amv6/7' arg for it to work, without this it will not compile and complains of missing headers.

When I pass the same argument list to the clang_complete user options in ~/.vimrc, autocomplete fails to resolve and warns that the -arch argument is not supported.

Do you have any suggestions on how I can work around this? I really want to be able to use clang_complete for my iOS project. (The project is a huge mix of C++, Obj-C and Obj-C++ files, if that is relevant).

Thanks! Sam

darkFunction commented 13 years ago

Hmmm I had a look through the source (I don't know python) but the arguments from the user options in .vimrc seem to be passed through to libclang. So maybe the problem is in libclang not supporting as many arguments as the clang executable?

There is a related question here: http://stackoverflow.com/questions/7697831/using-clang-complete-with-os-x-frameworks

xavierd commented 13 years ago

Hi,

I got absolutely no idea why clang is dismissing the -arch when asking for completion. Either it's not needed or it's a bug in clang. Usually when header are not find, it means that you forgot a -I or -F flag (the -isysroot flag may also be needed). You could look at the output of "strace -e trace=execve -f clang ..." to see if flags are not automatically added.

I'm sorry but I can't help you much, I don't own a Mac... If by chance you find what's missing, please tell us :)

darkFunction commented 12 years ago

Ok, apparently clang_complete uses clang -cc1 (frontend) and not clang (the driver). Not all arguments to the frontend are passed to the driver.

See here: http://stackoverflow.com/questions/7697831/using-clang-complete-with-os-x-frameworks/7874704#7874704

I am having trouble compiling any OSX framework-linked code using the -cc1 option. I think I need to speak to some clang gurus. The cc1 option isn't even documented :/

darkFunction commented 12 years ago

I got this working using

let g:clang_user_options='-triple x86_64-apple-macosx10.6.7 -target-cpu core2 -target-linker-version 123.2 -resource-dir /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/../lib/clang/2.1 -fblocks -x objective-c++ -fblocks -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -D__IPHONE_OS_VERSION_MIN_REQUIRED=40300 || exit 0'