OCLint 未能发现 pre-compiled workspace/project headers

OCLint fails to discover pre-compiled workspace/project headers

我在尝试构建我的 OCLint 聚合时收到以下错误。

我们在工作区内使用 pre-compiled headers,虽然它们在主要目标和 OCLint 聚合中的引用完全相同,但出于某种原因,OCLint 聚合无法发现 pch。

这就是找不到“CocoaLumberjack/CocoaLumberjack.h”依赖项的原因。

我是 运行 Xcode 7.1.1 OS X 10.11.1

*=== BUILD TARGET [Target] OF PROJECT [Project] WITH CONFIGURATION Debug ===
Check dependencies
ProcessPCH /var/folders/nv/y04q5c5s30567pk7w8lts7zr0000gn/C/com.apple.DeveloperTools/7.1.1-7B1005/Xcode/7.1.1-7B1005/Xcode/SharedPrecompiledHeaders/[Project]-Prefix-canqfypuftycqgglhiqfotrflhkv/[Project]-Prefix.pch.pch [Project]/[Project]-Prefix.pch normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/.../Dev/Applications/[Project]
    export LANG=en_US.US-ASCII
    export 

PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/.../StaticCodeAnalysis/OBJ-C/OCLint/oclint-0.8.1/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/usr/local/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/local/bin:/Applications/Xcode.app/Contents/Developer/Tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

   :
   :
/Users/.../Dev/Applications/[Project]/[Project]/[Project]-Prefix.pch:16:9: fatal error: 'CocoaLumberjack/CocoaLumberjack.h' file not found
[#import] <CocoaLumberjack/CocoaLumberjack.h>

        ^
1 error generated.
** BUILD FAILED **
[Project]

The following build commands failed:
    ProcessPCH /var/folders/nv/y04q5c5s30567pk7w8lts7zr0000gn/C/com.apple.DeveloperTools/7.1.1-7B1005/Xcode/7.1.1-7B1005/Xcode/SharedPrecompiledHeaders/[Project]-Prefix-canqfypuftycqgglhiqfotrflhkv/[Project]-Prefix.pch.pch [Project]/[Project]-Prefix.pch normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)*

更新: 我能够通过发出以下命令解决此问题:

xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme

我在尝试 run OCLint via pre-commit 时 运行 在 macOS Monterey (12.2) 上遇到了这个问题。来自 OCLint 的错误消息暗示缺少“编译数据库”,然后为系统 C 标准库 headers.

提供 'stdio.h' file not found

手动解决

解决方案是确保compile_commands.json 文件存在于top-level C 构建目录中。如果您使用 CMake,这显然是自动生成的,但该项目未使用 CMake。

手动创建文件成功:

compile_commands.json:

[
{
  "directory": ".",
  "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -o enum-test.arm64.o -c enum-test.c",
  "file": "enum-test.c"
},
{
  "directory": ".",
  "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -o test-args.arm64.o -c test-args.c",
  "file": "test-args.c"
},
{
  "directory": ".",
  "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -o test-vars.arm64.o -c test-vars.c",
  "file": "test-vars.c"
},
{
  "directory": ".",
  "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -o cidr_ranges.arm64.o -c cidr_ranges.c",
  "file": "cidr_ranges.c"
},
{
  "directory": ".",
  "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -o rectangle.arm64.o -c rectangle.c",
  "file": "rectangle.c"
}
]

OCLint 错误信息:

对于我的情况,在为 .h header 文件提供 file not found 之前,错误提示缺少 compile_commands.json

$ oclint  -enable-global-analysis -enable-clang-static-analyzer -max-priority-3 0  ./enum-test.c  -p=build -verbose --extra-arg -isysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk

Error while trying to load a compilation database:
Could not auto-detect compilation database from directory "build"
No compilation database found in ~/src/spikes/c-variables-and-data-types/build or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.

Compiling ~/src/spikes/c-variables-and-data-types/enum-test.c ...
 - Failed
Clang Static Analyzer ~/src/spikes/c-variables-and-data-types/enum-test.c - Finished with Failure

Compiler Errors:
(please be aware that these errors will prevent OCLint from analyzing this source code)

~/src/spikes/c-variables-and-data-types/enum-test.c:8:10: 'stdio.h' file not found

Clang Static Analyzer Results:

~/src/spikes/c-variables-and-data-types/enum-test.c:8:10: 'stdio.h' file not found


OCLint Report

Summary: TotalFiles=0 FilesWithViolations=0 P1=0 P2=0 P3=0


[OCLint (https://oclint.org) v21.10]