Use --sandbox_debug to see verbose messages from the sandbox clang: error: unknown argument: '-fno-canonical-system-headers' Target //main:hello-world failed to build Use --verbose_failures to see the command lines of failed build steps. INFO: Elapsed time: 0.287s, Critical Path: 0.11s INFO: 0 processes. FAILED: Build did NOT complete successfully
The version information of gcc and bazel that I’m using is
bazel clean # it doesn't work bazel clean --expunge # it works!!!
It works once cleaned with --expunge!
Why
The issue was actually caused by outdated gcc version, it should be fixed by updating XCode. However, it requires bazel clean to remove the working tree. The bazel clean only cleans the repository, while bazel clean --expunge completely removes the entire working tree created by a Bazel instance.