2

Namespacing headers in C++ is as easy as wrapping the header in

namespace SomeNs { ... }

Namespacing the corresponding the object file or static library wasn't straightforward because of name mangling, but I seem to have found a way regardless

On the other hand, plain C object files / static libraries should be even easier to namespace because there's already objcopy --prefix-symbols and C doesn't mangle symbols, but What is the objcopy --prefix-symbols counterpart for header files?

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
  • I don't think there is one. – Iharob Al Asimi Jun 29 '15 at 11:33
  • It is exactly what you already suggested. Put the namespace declaration around every `#include` naming the header in question, or put it directly in the file. If the latter, you can protect it with conditional compilation directives so that the namespace declaration is seen only when you compile in C++ mode. The latter is probably more reliable, and it is the same treatment often given to `extern "c"` declarations (which you must *avoid*, as it normally suppresses name mangling). – John Bollinger Jun 29 '15 at 11:48
  • 2
    See: http://stackoverflow.com/questions/6940384/how-to-deal-with-symbol-collisions-between-statically-linked-libraries – Toby Jun 29 '15 at 13:06
  • @Toby Thanks but I would really like an automated/automatable solution. – Petr Skocik Jun 29 '15 at 13:25
  • 1
    I'm an idiot. Of course that method is automatable, ;D I just got to get the symbols for the redefines from the corresponding object file (with `nm`) rather than from the header file (don't know how to do that). – Petr Skocik Jun 29 '15 at 17:58

0 Answers0