unable to compile bazel from source on Mac, getting clang: error: unknown argument: '-fno-canonical-system-headers'

3,563 views
Skip to first unread message

Janak Ramakrishnan

unread,
Mar 23, 2017, 5:40:21 PM3/23/17
to bazel-discuss
On a fresh Macbook, I followed the instructions at https://bazel.build/contributing.html and install.html: first I installed JDK 8 from Oracle. Then I downloaded Bazel using an installer downloaded from https://github.com/bazelbuild/bazel/releases. I installed it, and tried to run "bazel build //src:bazel". This initially failed with:

bazel build //src:bazel
............
INFO: Found 1 target...
ERROR: /Users/janakr/bazel/tools/osx/BUILD:17:1: Executing genrule //tools/osx:xcode-locator-genrule failed: bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.
Target //src:bazel failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 6.938s, Critical Path: 1.79s

But popped up a dialog about installing Xcode developer tools. I installed them, and tried again. Then I got:

bazel build //src:bazel

INFO: Found 1 target...

ERROR: /Users/janakr/bazel/src/main/tools/BUILD:28:1: C++ compilation of rule '//src/main/tools:linux-sandbox' failed: Process exited with status 1 [sandboxed].

clang: error: unknown argument: '-fno-canonical-system-headers'

Use --strategy=CppCompile=standalone to disable sandboxing for the failing actions.

Target //src:bazel failed to build

Use --verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 1.716s, Critical Path: 1.31s

Turning off sandboxing made no difference. Now I've installed the full Xcode package from the App Store (which I didn't want to do initially, since I don't develop iOS apps). I accepted the license agreement by running sudo gcc --version, but I'm still getting an error:

bazel build //src:bazel

INFO: Found 1 target...

ERROR: /Users/janakr/bazel/src/main/tools/BUILD:20:1: C++ compilation of rule '//src/main/tools:build-runfiles' failed: Process exited with status 1 [sandboxed].

clang: error: unknown argument: '-fno-canonical-system-headers'

Use --strategy=CppCompile=standalone to disable sandboxing for the failing actions.

Target //src:bazel failed to build

Use --verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 1.406s, Critical Path: 1.21s

Any advice?

Marcel Hlopko

unread,
Mar 27, 2017, 4:32:34 AM3/27/17
to Janak Ramakrishnan, bazel-discuss
Hi Janak,

sorry for the slow reply. Still fighting with this? The flag comes from tools/cpp/cc_configure.bzl and is guarded by our (arguably quite naive :) autodetection logic. So if your gcc/clang doesn't provide the flag, it shouldn't be emitted. Can you take a look what your gcc returns for: 

echo 'int main() {}' > empty.cc
gcc -fno-canonical-system-headers -o /dev/null -c empty.cc

Also, what's your gcc/clang version?

Thanks Janak!

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHDrXd1gaPoBKbg-29idE7X17XOY-ocVZ0xad5%2BJ6TCaAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle | Registergericht und -nummer: Hamburg, HRB 86891

Damien Martin-Guillerez

unread,
Mar 27, 2017, 4:34:21 AM3/27/17
to Marcel Hlopko, Janak Ramakrishnan, bazel-discuss, kcho...@google.com
Hi Janak,

I believe you need to install Xcode. +Kristina Chodorow hitted that issue the other time.

Janak Ramakrishnan

unread,
Mar 27, 2017, 10:09:52 PM3/27/17
to Damien Martin-Guillerez, Marcel Hlopko, bazel-discuss, kcho...@google.com
Thanks for the help! @hlopko: running what you suggested gives me the
same error:
clang: error: unknown argument: '-fno-canonical-system-headers'

$ gcc --version

Configured with:
--prefix=/Applications/Xcode.app/Contents/Developer/usr
--with-gxx-include-dir=/usr/include/c++/4.2.1

Apple LLVM version 8.0.0 (clang-800.0.42.1)

Target: x86_64-apple-darwin16.4.0

Thread model: posix

InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@dmarting: I didn't install Xcode initially, but I did install it
later and still saw the same error. I just opened Xcode and it asked
me if I wanted to install additional required components for running
and debugging. I did that, but nothing changed, still the same error
(and same gcc version).

Marcel Hlopko

unread,
Mar 29, 2017, 3:44:00 AM3/29/17
to Janak Ramakrishnan, Damien Martin-Guillerez, bazel-discuss, kcho...@google.com
Super strange, I have the same gcc version, and the flag is not emitted. Could it be that when you first run bazel it created crosstool for different compiler? Could you post the content of the crosstool (outputbase/external/local_config_cc/CROSSTOOL)? Does `bazel clean` change anything?


For more options, visit https://groups.google.com/d/optout.

Janak Ramakrishnan

unread,
Mar 29, 2017, 9:53:48 AM3/29/17
to Marcel Hlopko, Damien Martin-Guillerez, bazel-discuss, kcho...@google.com
CROSSTOOL attached. bazel clean doesn't help. Thanks!
CROSSTOOL

Marcel Hlopko

unread,
Mar 29, 2017, 10:55:04 AM3/29/17
to Janak Ramakrishnan, Damien Martin-Guillerez, bazel-discuss, kcho...@google.com
Sorry Janak, it should've been `bazel clean --expunge`
Clean is not cleaning repositories...

Janak Ramakrishnan

unread,
Mar 29, 2017, 10:39:23 PM3/29/17
to Marcel Hlopko, Damien Martin-Guillerez, bazel-discuss, kcho...@google.com
Thanks Marcel, clean --expunge did the trick! So it's quite dangerous to run bazel before installing Xcode!


>> >>> To view this discussion on the web visit
>> >>>
>> >>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHDrXd1gaPoBKbg-29idE7X17XOY-ocVZ0xad5%2BJ6TCaAg%40mail.gmail.com.
>> >>> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> --
>> >> Marcel Hlopko | Software Engineer | hlo...@google.com |
>> >>
>> >> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
>> >> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
>> >> Registergericht und -nummer: Hamburg, HRB 86891
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "bazel-discuss" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/bazel-discuss/CAFuL9GmfnyZ-dh%2BmCbCgM2C0zcCf0RW5sqPOD8sGVWr-a6Wr6A%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "bazel-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHAAeWciAXtj7zStoBcuGkdKfDFkSnyf4pyAyHr2_pe%2B-w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> Marcel Hlopko | Software Engineer | hlo...@google.com |
>
> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
> Registergericht und -nummer: Hamburg, HRB 86891

Damien Martin-Guillerez

unread,
Mar 30, 2017, 2:48:04 AM3/30/17
to Janak Ramakrishnan, Marcel Hlopko, bazel-discuss, kcho...@google.com

That's bad, which version of Bazel? I'll get a new Mac soonish and try that.



>> >>> To view this discussion on the web visit
>> >>>
>> >>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHDrXd1gaPoBKbg-29idE7X17XOY-ocVZ0xad5%2BJ6TCaAg%40mail.gmail.com.
>> >>> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> --
>> >> Marcel Hlopko | Software Engineer | hlo...@google.com |
>> >>
>> >> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
>> >> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
>> >> Registergericht und -nummer: Hamburg, HRB 86891
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "bazel-discuss" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/bazel-discuss/CAFuL9GmfnyZ-dh%2BmCbCgM2C0zcCf0RW5sqPOD8sGVWr-a6Wr6A%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "bazel-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHAAeWciAXtj7zStoBcuGkdKfDFkSnyf4pyAyHr2_pe%2B-w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> Marcel Hlopko | Software Engineer | hlo...@google.com |
>
> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
> Registergericht und -nummer: Hamburg, HRB 86891

Damien Martin-Guillerez

unread,
Mar 30, 2017, 2:50:16 AM3/30/17
to Janak Ramakrishnan, Marcel Hlopko, bazel-discuss, kcho...@google.com

Oh. I think I figured out. The first run configured the c++ toolchain without xcode and installing xcode changed the c++ toolchain but we don't track those change. Anyway I'll try that when I get my new Mac to see if we can do better.

Marcel Hlopko

unread,
Mar 30, 2017, 3:19:59 AM3/30/17
to Damien Martin-Guillerez, Janak Ramakrishnan, bazel-discuss, kcho...@google.com
Yup, exactly, first run must have configured crosstool for different compiler (or maybe we also configure crosstool for no compiler at all! I'll check that). Let's see what we can do with your mac Damien :)
Thanks Janak!

Damien Martin-Guillerez

unread,
May 5, 2017, 7:06:52 AM5/5/17
to Marcel Hlopko, Janak Ramakrishnan, bazel-discuss, kcho...@google.com
Got my new mac, trying it with 0.4.5rc3

Damien Martin-Guillerez

unread,
May 5, 2017, 7:25:32 AM5/5/17
to Marcel Hlopko, Janak Ramakrishnan, bazel-discuss, kcho...@google.com
I cannot seem to arrive that far, it ask me to get Xcode, getting only the command line tools fails miserably :(

Peter Schmitt

unread,
May 5, 2017, 9:00:34 AM5/5/17
to Damien Martin-Guillerez, Marcel Hlopko, Janak Ramakrishnan, bazel-discuss, kcho...@google.com
You have to install Xcode and run it at least once (agreeing to license term). Anything else is unlikely to work.


>> >>> To view this discussion on the web visit
>> >>>
>> >>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHDrXd1gaPoBKbg-29idE7X17XOY-ocVZ0xad5%2BJ6TCaAg%40mail.gmail.com.
>> >>> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> --
>> >> Marcel Hlopko | Software Engineer | hlo...@google.com |
>> >>
>> >> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
>> >> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
>> >> Registergericht und -nummer: Hamburg, HRB 86891
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "bazel-discuss" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> To view this discussion on the web visit
>> >>
>> >> https://groups.google.com/d/msgid/bazel-discuss/CAFuL9GmfnyZ-dh%2BmCbCgM2C0zcCf0RW5sqPOD8sGVWr-a6Wr6A%40mail.gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "bazel-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHAAeWciAXtj7zStoBcuGkdKfDFkSnyf4pyAyHr2_pe%2B-w%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> Marcel Hlopko | Software Engineer | hlo...@google.com |
>
> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
> Registergericht und -nummer: Hamburg, HRB 86891
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle | Registergericht und -nummer: Hamburg, HRB 86891
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle | Registergericht und -nummer: Hamburg, HRB 86891

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAN3hOS8TFe-21EgqpxpCeAsv0Y%3DWTjpfMeTNt5PUgT64u5W13Q%40mail.gmail.com.

sabine....@gmail.com

unread,
Aug 22, 2017, 9:28:15 PM8/22/17
to bazel-discuss, hlo...@google.com, dmar...@google.com, kcho...@google.com
I can confirm the same exact thing. Running bazel before a reinstall/update of Xcode and the --expunge worked.

On Wednesday, March 29, 2017 at 7:39:23 PM UTC-7, Janak Ramakrishnan wrote:
> Thanks Marcel, clean --expunge did the trick! So it's quite dangerous to run bazel before installing Xcode!
>
>
> On Wed, Mar 29, 2017 at 10:54 AM, Marcel Hlopko <hlo...@google.com> wrote:
>
> Sorry Janak, it should've been `bazel clean --expunge`
> Clean is not cleaning repositories...
>
>
>
>
> On Wed, Mar 29, 2017 at 3:53 PM Janak Ramakrishnan <jan...@google.com> wrote:
> CROSSTOOL attached. bazel clean doesn't help. Thanks!
>
>
>
> On Wed, Mar 29, 2017 at 3:43 AM, Marcel Hlopko <hlo...@google.com> wrote:
>
> > Super strange, I have the same gcc version, and the flag is not emitted.
>
> > Could it be that when you first run bazel it created crosstool for different
>
> > compiler? Could you post the content of the crosstool
>
> > (outputbase/external/local_config_cc/CROSSTOOL)? Does `bazel clean` change
>
> > anything?
>
> >
>
> > On Tue, Mar 28, 2017 at 4:09 AM 'Janak Ramakrishnan' via bazel-discuss
>
> >> > <bazel-...@googlegroups.com> wrote:
>
> >> >>
>
> >> >> Hi Janak,
>
> >> >>
>
> >> >> sorry for the slow reply. Still fighting with this? The flag comes from
>
> >> >> tools/cpp/cc_configure.bzl and is guarded by our (arguably quite naive
>
> >> >> :)
>
> >> >> autodetection logic. So if your gcc/clang doesn't provide the flag, it
>
> >> >> shouldn't be emitted. Can you take a look what your gcc returns for:
>
> >> >>
>
> >> >> echo 'int main() {}' > empty.cc
>
> >> >> gcc -fno-canonical-system-headers -o /dev/null -c empty.cc
>
> >> >>
>
> >> >> Also, what's your gcc/clang version?
>
> >> >>
>
> >> >> Thanks Janak!
>
> >> >>
>
> >> >> On Thu, Mar 23, 2017 at 10:40 PM 'Janak Ramakrishnan' via bazel-discuss
>
> >> >>> email to bazel-discus...@googlegroups.com.
>
> >> >>> To view this discussion on the web visit
>
> >> >>>
>
> >> >>> https://groups.google.com/d/msgid/bazel-discuss/CAF7sfHDrXd1gaPoBKbg-29idE7X17XOY-ocVZ0xad5%2BJ6TCaAg%40mail.gmail.com.
>
> >> >>> For more options, visit https://groups.google.com/d/optout.
>
> >> >>
>
> >> >> --
>
> >> >> --
>
> >> >> Marcel Hlopko | Software Engineer | hlo...@google.com |
>
> >> >>
>
> >> >> Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany |
>
> >> >> Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle |
>
> >> >> Registergericht und -nummer: Hamburg, HRB 86891
>
> >> >>
>
> >> >> --
>
> >> >> You received this message because you are subscribed to the Google
>
> >> >> Groups
>
> >> >> "bazel-discuss" group.
>
> >> >> To unsubscribe from this group and stop receiving emails from it, send
>
> >> >> an
>
> >> >> email to bazel-discus...@googlegroups.com.
>
> >> >> To view this discussion on the web visit
>
> >> >>
>
> >> >> https://groups.google.com/d/msgid/bazel-discuss/CAFuL9GmfnyZ-dh%2BmCbCgM2C0zcCf0RW5sqPOD8sGVWr-a6Wr6A%40mail.gmail.com.
>
> >> >> For more options, visit https://groups.google.com/d/optout.
>
> >>
>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups
>
> >> "bazel-discuss" group.
>
> >> To unsubscribe from this group and stop receiving emails from it, send an
>
> >> email to bazel-discus...@googlegroups.com.

shixiao...@gmail.com

unread,
Dec 5, 2017, 12:11:13 PM12/5/17
to bazel-discuss
在 2017年8月23日星期三 UTC+8上午9:28:15,sabine....@gmail.com写道:
I come cross this problem too, and "bazel clean --expunge" do work for me. I update Mac OS weeks ago, and I do configure before install Xcode, then the problem raise.
This is my bezel version msg:

Build label: 0.8.0-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Nov 27 20:38:20 2017 (1511815100)
Build timestamp: 1511815100
Build timestamp as int: 1511815100

我也遇到了这个问题,"bazel clean --expunge"可以解决这个问题。

senli...@zoom.us

unread,
May 15, 2020, 7:49:37 AM5/15/20
to bazel-discuss
Reply all
Reply to author
Forward
0 new messages