Support multiple symbol definitions in different libraries

I am trying to compile a project with two libraries A and B, which define the same symbol. The intention was for library B to override A’s definition, which I can normally achieve by specifying B first during linking, i.e., ld ... -lB -lA.

However, instead, I get a multiple definition error from Pio. I found that this was because the linker invocation was using the --whole-archive option, which instructs the linker to include all following symbol definitions in the linked binary.

I’m wondering if:

  1. It’s possible to bypass the --whole-archive option for these two libraries in particular, and
  2. if it’s possible to guarantee the link order for these libraries?

If it’s relevant, I’m building for the Zephyr platform.

I’m not using weak symbols because I’m trying to retain build environment compatability. In particular, clang/lld seems to have limited support for weak symbols.