经过更多研究后,我发现正确的方法是使用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
您可能需要根据您的系统配置更新一些参数,但这对我来说目前工作正常。