daedsidog
daedsidog

Reputation: 1773

Preventing namespace conflict from header-only library dependencies

I am developing a library component which can be used as a template-heavy header-only library. The library has its own namespace for all the functions it exports.

My problem is that the library makes use of other header-only libraries, with their own namespaces. If a user wants to include my header-only library, he will import my library's namespace and also the third party library namespaces. What this means is if the user happens to import both my library and one of my library's dependencies at the same time, there may be a conflict of versions and/or namespaces.

To make another thing clear, I bundle a certain version of the third-party libraries along with my own, and am required to use that specific version. There is no way to offload the third-party functionality to a .cpp file instead of the header.

I would like to know what is the best method to deal with this issue, or is it even worth dealing with. So far, I know only of two solutions, and both of them seem like bad practice to me:

  1. Including the dependencies under my library's namespace (tends to break things).
  2. Renaming every instance of ext_namespace:: to my_namespace::ext_namespace in the third-party library headers.

Upvotes: 0

Views: 153

Answers (0)

Related Questions