1

In our project team we applications for micro-controller targets with arm-none-eabi-gcc. For running our testrunner we compile using the native cc compiler.

In our project team most use a Linux os, but some us a windows os (for reasons). The issue we run into is that we use the C11 keyword _Static_assert. When compiling on Linux it works, but when compiling under windows we get the following error: error LNK2019: unresolved external symbol _Static_assert referenced in function {}

This is due to the reason that the default MSVC compiler implements ANSI C89 which doesn't support the _Static_assert symbol. MSVC - C standards support

It also specifies that adding the /std:c11 or /std:c17 compiler options enable the support for _Static_assert.

We already have enabled --enable_platform_specific_config for other reasons.

Simply adding the build:windows --copt="/std:c11" to the .bazelrc solves the issue but also breaks the normal application build because arm-none-eabi-gcc compiler doesn't support the /std:c11 compiler flag.

Question: How can i add the /std:c11 compiler flag so that it only propagates to the native msvc compiler and not to the rest of my build targets?

  • `build:windows` suggests that you're running `bazel --config=windows`. Do you also use `--config=windows` in a build that runs `arm-none-eabi-gcc`? – Nick Lewycky Sep 25 '22 at 19:41
  • I don't run `bazel --config=windows` explicitly. But it probably be implicit when building on windows – user2038134 Sep 25 '22 at 19:55
  • On Windows, do you run ARM gcc? Do you have some targets that are intended to be native and others which are intended to target ARM? Are the build rules for them marked somehow? – Nick Lewycky Sep 25 '22 at 19:55
  • 1
    For our project we cross compile for an ARM micro-controller, using the `arm-none-eabi-gcc` compiler. So yes under window i invoke the arm gcc compiler to cross compile – user2038134 Sep 25 '22 at 19:58
  • Try `build:windows --host_copt="/std:c11"` in your `.bazelrc`? – Nick Lewycky Sep 25 '22 at 19:59
  • To bad, same error: `error LNK2019: unresolved external symbol _Static_assert referenced in function {}` – user2038134 Sep 25 '22 at 20:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248337/discussion-between-nick-lewycky-and-user2038134). – Nick Lewycky Sep 25 '22 at 20:05

1 Answers1

1

When using MSVC for host builds (when building a tool that emits source code which is then #include'd, for example protocol buffer compiler) add build:windows --host_copt="/std:c11". When using MSVC for test builds, add test:windows --host_copt="/std:c11". Don't put it in build:windows --copt because that will apply even when running builds to the target.

Nick Lewycky
  • 1,182
  • 6
  • 14