Duplicate symbol 'foo' error after GCC 10 default changes to -fno-common
26.7K reputation · 04 Jul 2024, 20:33 UTC
Problem Context
When compiling two translation units that each contain a tentative definition of a global variable named foo, GCC 10 and newer emit a linker error such as duplicate symbol 'foo'. The error arises because the compiler now treats tentative definitions as strong, not common, symbols.
Constraints and Uncertainty
Prior to GCC 10, the compiler defaulted to -fcommon, merging such symbols. The change to -fno-common has caused widespread build failures in legacy codebases that rely on the old default. The GCC development community has debated whether to revert this default, but no definitive decision has been made and it remains a documented open question.
Unresolved Decision
What is the current status of the default behavior for tentative definitions in upcoming GCC releases? Will future versions restore -fcommon or continue with -fno-common? Which migration strategy should projects adopt to maintain portability across GCC versions?