two projects using source of the same library twice

611 views Asked by At

I have a library Lib and an executable App with the following file hierarchy:

Lib/
  - external/
       - pugixml/
            - pugixml.hpp -> namespace ``pugi`` and header guard ``LIBA_PUGIXML_HPP``
            - pugixml.cpp 
App/
  - external/
       - pugixml/
            - pugixml.hpp  ->  namespace ``pugi`` and header guard ``APP_PUGIXML_HPP``
            - pugixml.cpp 

Both App and Lib use the external library pugixml (might be different versions). They include thes files directly in the project and pugixml is no external dependency anymore basically.

App depends on Lib and includes all necessary sources from Lib (it does not link with Lib) to successfully compile itself.

How can I avoid namespace clashes of the pugixml.hpp library which arises when compiling App. How can I use two different versions of the same library in this setting?

I see the following options:

  • Move namespaces pugixml in A into namespace A{ namespace pugixml {...} }, and the same in app : move namespaces pugixml in app into namespace app{ namespace pugixml {...} }

  • Rename all namespaces ? How should I do this? Hardcoding? or is there a c++ syntax for this?

What is a good approach?

0

There are 0 answers