在导入Foundation的Objective-C文件上运行Clang查询

时间:2019-03-27 07:13:41

标签: c++ clang llvm-clang foundation clang-query

我正在尝试使用clang-query对导入Foundation但无法正常工作的obj-c文件运行匹配,将clang-query移至tools/extra文件夹中后,我使用此命令:

./clang-query MyClass.m -- -extra-arg-before "-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk"

但是我遇到了这个错误:

 fatal error: 'stdarg.h' file not found
#include <stdarg.h>

我应该如何运行clang-query来分析我的Objective-c资源?

1 个答案:

答案 0 :(得分:0)

经过更多研究,我发现正确的方法是使用基于libTooling的工具。如他们的文档所述:

Clang Tooling needs a compilation database to figure out specific build options for each file. Currently it can create a compilation database from the compile_commands.json file

对于Xcode项目,可以这样生成该文件:

xcodebuild -project PROJECT_NAME.xcodeproj | xcpretty -r json-compilation-database --output compile_commands.json

您将需要安装xcpretty gem。 (gem install xcpretty

来源:https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html

更新: 如果像我一样,您在从xcodebuild日志生成的compile_commands.json文件中遇到问题,只需将此命令传递给您的二进制文件即可:

-mios-simulator-version-min=10.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.00/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks

您可能需要根据您的系统配置来更新一些参数,但这对我来说目前还可以。