Questions tagged [weak-symbol]

A weak symbol denotes a specially annotated symbol during linking of elf object files.

A weak symbol denotes a specially annotated symbol during linking of elf object files. By default, without any annotation, a symbol in an object file is strong. During linking, a strong symbol can override a weak symbol of the same name. In contrast, 2 strong symbols that share a name yield a link error during compile-time. When linking a binary executable, a weakly declared symbol does not need a definition. In comparison, (by default) a declared strong symbol without a definition triggers an undefined symbol link error.

Weak symbols are not mentioned by C or C++ language standards; as such, inserting them into code is not very portable. Even if two platforms support the same or similar syntax for marking symbols as weak, the semantics may differ in subtle points, e.g. if weak symbols during dynamic linking at runtime lose their semantics or not.

17 questions
0
votes
1 answer

What is the gcc equivalent of the -qnoweakexp xlC compiler flag?

We are currently migrating from AIX and the xlC compiler to Linux and the GNU toolchain. In our C/C++ compilation process we use the -qnoweakexp compiler flags to disable the export of weak symbols. Please see the xlc compiler reference. I cannot…
Gábor Ferencz
  • 243
  • 2
  • 9
0
votes
0 answers

What is the Windows equivalent of `__attribute__((weak))`?

I'm trying to port a GNU project to Windows and I ran across the following GNU syntax... extern void serialEventRun(void) __attribute__((weak)); What is the Windows equivalent to this, or how does Windows handle weak symbols?
Zak
  • 12,213
  • 21
  • 59
  • 105
1
2