http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46097
--- Comment #17 from Jeffrey Walton <noloader at gmail dot com> 2010-10-21 16:59:55 UTC --- (In reply to comment #16) > (In reply to comment #13) > > > > Good point: here's what I would recommend: common sense. Myself, Alexey, a > > number of packagers across the globe, and untold others have performed this > > ODR > > violation. Since you know more about the subject matter than me (I would > > like > > to think of you as a SME - subject matter expert), what would you recommend > > so > > that folks like myself, Alexey, distribution packagers, and others don't go > > shooting ourselves in the foot? > > There are a number of options for making sure the global is private to the > library, thus avoiding multiple definitions of the same object when two copies > of the code are linked to. > > * You can make the global object have static linkage. > > * You can put it in an anonymous namespace. > > * You can give it non-global visibility. For completeness, Crypto++ used: GlobalVariable& GetGlobalVariable() { static GlobalVariable globalVariable; return globalVariabl } And Vladimir Simonov recommended (http://gcc.gnu.org/ml/gcc-help/2010-10/msg00256.html): -fvisibility=hidden Lots of good mechanisms. Unfortunately, it's not readily apparent when they need to be used by whom. I think GCC could be of great assistance to the average developer and packager. You (and most likely other folks at GCC) clearly understand the problem. Can you help us with a reasonable warning to 'save us from ourselves'? After all, a warning can be turned of or ignored. But if a warning does not exist, it does not help at all :/ Jeff