0

Im building a shared library which itself has a dependency on another shared library. These dependencies are not exposed by the library, for example

In Library A:


class MySubDependencyClass{

}

In Library B:

class MyLibraryClass{
public:
   void foo(){
      mySubDependencyClass.foo()
   }
private:
MySubDependencyClass mySubDependencyClass;
}

In my Application:

class MyAppClass{
  MyLibraryClass myLibrary class
}

The dependency chain looks like this MyApp -> MyLibrary ->MySubDependency

When building MyApp at the moment I have to link the subdependencies as well as the direct dependency. Is there any way to get around this? It seems very unelegant.

I found this link: Linking with dynamic library with dependencies but couldn't understand if the issue was resolved or not

My IDE is qtcreator.

EDIT:

I have now forward declared the subdependency

In Library B:

class MySubDependencyClass;

class MyLibraryClass{
public:
   void foo(){
      mySubDependencyClass.foo()
   }
private:
MySubDependencyClass mySubDependencyClass;
}

and this works, is this the way to go? What is the "standard" way of dealing with this?

Claude Hasler
  • 396
  • 1
  • 14
  • Do you use any of the SubDependency functions in your application? – vahancho Oct 16 '19 at 13:14
  • "These dependencies are not exposed by the library" this is not correct, just because `mySubDependencyClass` is private doesn't mean it is not part of your libraries interface. There needs to be no instances of library a's classes in library b's public headers – Alan Birtles Oct 16 '19 at 13:19
  • @vahancho no i do not, or if i do, then they are wrapped – Claude Hasler Oct 16 '19 at 13:33
  • @AlanBirtles How would i wrap the subdependency correctly to get around this? – Claude Hasler Oct 16 '19 at 13:34
  • either hide it completely using the pimpl pattern or you might be able to get away with forward declaring `MySubDependencyClass` in `MyLibraryClass` and making `mySubDependencyClass` a pointer (preferrably a smart one) – Alan Birtles Oct 16 '19 at 13:38
  • @AlanBirtles thanks, the forward declaration worked, ill check out the pimpl pattern – Claude Hasler Oct 16 '19 at 13:42

0 Answers0