How to deal with symbol collisions between statically linked libraries?

Viewed 39354

One of the most important rules and best practices when writing a library, is putting all symbols of the library into a library specific namespace. C++ makes this easy, due to the namespace keyword. In C the usual approach is to prefix the identifiers with some library specific prefix.

Rules of the C standard put some constraints on those (for safe compilation): A C compiler may look at only the first 8 characters of an identifier, so foobar2k_eggs and foobar2k_spam may be interpreted as the same identifiers validly – however every modern compiler allows for arbitrary long identifiers, so in our times (the 21st century) we should not have to bother about this.

But what if you're facing some libraries of which you cannot change the symbol names / idenfiers? Maybe you got only a static binary and the headers or don't want to, or are not allowed to adjust and recompile yourself.

3 Answers
Related