2

我正在尝试使用 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 源?

4

1 回答 1

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

您将需要安装xcprettygem。( 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

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

于 2019-03-29T09:48:46.917 回答