如何为Xcode项目指定其他clang选项? [英] How can I specify additional clang options for Xcode project?

查看:477
本文介绍了如何为Xcode项目指定其他clang选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 clang 插件-part-iii-plugin-example /rel =nofollow>本教程
,我想在我的Xcode iOS项目上自动运行它。



我需要对 clang

运行以下附加命令

  -Xclang -load \ 
-Xclang〜/ static_analysis / llvm / Debug + Asserts / lib / libPluginExample.so \
-Xclang -plugin - Xclang -example-plugin \

我想保存Xcode生成的所有其他命令,因为它很难为每个Xcode项目创建和传递这些命令。这就是为什么我选择使用 clang 插件,而不是 clang 工具的原因。



我如何做到这一点?



或者我如何提取由xcode生成的编译器标志aoutomtically,使用它们在cl工具? (becouse,正确使用工具,我需要指定所有包含目录,所有来源和所有框架)



更新: >

我在Project中添加了以下命令


设置 - >构建阶段 - >编译源(双击源代码)



,但在编译时出现错误(插件是标准示例libPrintFunctionNames.dylib clang sources):


错误:无法加载插件
'/Users/...llvm/Debug+Asserts/lib /libPrintFunctionNames.dylib':
'dlopen(/ Users /.../ llvm / Debug + Asserts / lib / libPrintFunctionNames.dylib,
9):找不到符号:
__ZN5clang11ASTConsumer21HandleInterestingDeclENS_12DeclGroupRefE引用自:
/Users/.../llvm/Debug+Asserts/lib/libPrintFunctionNames.dylib
预期在:
中的flat命名空间/Users/.../llvm/Debug+Asserts/ lib / libPrintFunctionNames.dylib'
命令/应用程序/ Xcode
2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
失败,退出代码为1


我试图使用 libPrintFunctionNames.a ,而不是 libPrintFunctionNames .dylib ,但它不帮助。



也许原因是我在分离的源文件llvm和clang上构建我的插件,在xcode我使用其他版本的ang。

解决方案

我将在构建选项OTHER_CFLAGS中指定其他Clang选项。您可以在

  target / project Build Settings  - > Apple LLVM 5.0  - 自定义编译器标志 - >其他C旗帜

也可以为 xcodebuild ,例如

  xcodebuild -scheme SampleProject build OTHER_CFLAGS = -  Xclang -load -Xclang / path / to / libPrintFunctionNames .dylib -Xclang -plugin -Xclang print-fns

xcodebuild 是很方便的,当你不想保持只有OTHER_CFLAGS不同的2个目标。



但你是对的,看起来你真的需要链接到与铛本身链接的相同的库。至少我从 http://llvm.org/releases/download.html下载了Clang + LLVM 3.3二进制文件,构建了带有下载的库的插件,它与 http://llvm.org 的clang一起使用,但doesn从Xcode的clang工作 - 我遇到以下错误:

 错误:无法找到插件'print-fns'

我创建了Xcode工作区,它构建了Clang插件,并展示了如何尝试使用默认iOS应用。您可以在 https://github.com/vsapsai/ClangPluginExample

找到它

I have created my custom clang plugin with help of this tutorial and I want to run it automatically on my Xcode iOS project.

I need to run following additional commands on clang,

-Xclang -load \
-Xclang ~/static_analysis/llvm/Debug+Asserts/lib/libPluginExample.so \
-Xclang -plugin -Xclang -example-plugin \

I would like to save all other commands generated by Xcode, because it is difficult to create and pass those commands for every Xcode project. That is the reason why I choose to use clang plugin but not clang tool.

How can I do achieve this?

Or how can I extract compiler flags generated by xcode aoutomtically, to use them in clang tool? (becouse, for correct using tool I need to specify all include directories, and all sources, and all frameworks)

Update:

I have added thous commands in Project

Settings -> Build Phases -> Compile Sources (double click on source)

, but in compile time there is error (plugin is standard example libPrintFunctionNames.dylib from clang sources):

error: unable to load plugin '/Users/...llvm/Debug+Asserts/lib/libPrintFunctionNames.dylib': 'dlopen(/Users/.../llvm/Debug+Asserts/lib/libPrintFunctionNames.dylib, 9): Symbol not found: __ZN5clang11ASTConsumer21HandleInterestingDeclENS_12DeclGroupRefE Referenced from: /Users/.../llvm/Debug+Asserts/lib/libPrintFunctionNames.dylib Expected in: flat namespace in /Users/.../llvm/Debug+Asserts/lib/libPrintFunctionNames.dylib' Command /Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1

I have tried to use libPrintFunctionNames.a instead of libPrintFunctionNames.dylib, but it doe not help.

Maybe the cause is that I built my plugin on separated source files of llvm and clang, and in xcode I use other version of clang. I will check that.

解决方案

I would specify additional Clang options in build option OTHER_CFLAGS. You can do so in

target/project Build Settings -> Apple LLVM 5.0 - Custom Compiler Flags -> Other C Flags

Or you can specify OTHER_CFLAGS for xcodebuild, for example,

xcodebuild -scheme SampleProject build OTHER_CFLAGS="-Xclang -load -Xclang /path/to/libPrintFunctionNames.dylib -Xclang -plugin -Xclang print-fns"

xcodebuild is convenient when you don't want to maintain 2 targets which differ only in OTHER_CFLAGS.

But you're right, it looks like you really need to link against the same libraries as clang itself is linked. At least I've downloaded Clang+LLVM 3.3 binaries from http://llvm.org/releases/download.html , built the plugin with downloaded libraries and it works with clang from http://llvm.org, but doesn't work with clang from Xcode - I encounter the following error:

error: unable to find plugin 'print-fns'

I've created Xcode workspace which builds Clang plugin and shows how you can try to use it with default iOS application. You can find it at https://github.com/vsapsai/ClangPluginExample

这篇关于如何为Xcode项目指定其他clang选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆