c++ - 在导入 Foundation 的 objective-c 文件上运行 Clang-query

标签 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 源代码?

最佳答案

经过更多研究后,我发现正确的方法是使用基于 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 安装 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

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

关于c++ - 在导入 Foundation 的 objective-c 文件上运行 Clang-query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371670/

相关文章:

c++ - 在 C++ 中对 CreateFile 和 ReadFile 的异步调用

c++ - 放大纹理时如何关闭 OpenGL 过滤?

c++ - clang 重新定义不同 namespace 中的符号错误

c++ - 如何从 .ll 文件 LLVM 获取源代码行号

javascript - 如何使用 Emscripten 将对象从 Javascript 传递到 C++

Objective-C代码分析

C++:从外部在类内声明枚举器,因此可以在私有(private)成员中使用

c++ - 连接两个std::vector

objective-c - 编译器不会将每个变量都视为 __block 变量的原因是什么?

c++ - 运算符转换、GCC 和 clang : which compiler is right?