OCLint fails to discover pre-compiled workspace/project headers

425 Views Asked by At

I am receiving the error below when attempting to build my OCLint aggregate.

We use pre-compiled headers within the workspace and although they are referenced exactly the same within the main target and OCLint aggregate, for some reason,OCLint aggregate is unable to discover the pch.

This is why the "CocoaLumberjack/CocoaLumberjack.h" dependency can't be found.

I am running Xcode 7.1.1 under 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)*
2

There are 2 best solutions below

0
On BEST ANSWER

Update: I was able to solve this problem by issuing the following command:

xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme
0
On

I ran into this problem on macOS Monterey (12.2) while trying to run OCLint via pre-commit. The error message from OCLint was hinting at a missing "Compilation Database", then giving a 'stdio.h' file not found for the system C standard library headers.

Manual Solution

The solution was to make sure that a compile_commands.json file existed at the top-level C build directory. This is apparently generated automatically if you use CMake, but the project was not using CMake.

Creating the file manually worked:

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 error message:

For my case, the error hinted at the missing compile_commands.json before giving the file not found for .h header files:

$ 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]