Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

URGENT Circular dependency problem

Ok, I have two libraries:


Corelib contains a function called 'InterpretCommand', which needs to be accessible through 'netlib'.

'InterpretCommand' on the other hand needs access to a class in 'netlib', 'ClientSocket'. Therefore 'netlib' and 'corelib'.

Referencing 'netlib' in 'corelib' works good, but when I try to reference 'netlib' in 'corelib' it tells me it's not possible since it would create circular dependencies.

Any solution?
  • 2
1 Solution
The only way to solve linker circular dependency is to create third library and move some classes to it. Result should be:
corelib depends on new library
netlib depends on new library.

Compiler #include circular dependency can be solved using forward declaration and pointers. If library exports functions, circular dependency can be solved using dynamic linking (LoadLibrary). When library exports classes, the only way is creating new library.
bjqrnAuthor Commented:
Could you explain the "new library" part a bit further?
ClientSocket class must be moved to new library. Create new library project and move this class to it. Let's call it socketlib.
netlib calls InterpretCommand from corelib
corelib calls ClientSocket from socketlib.

netlib project - corelib
corelib project - socketlib.

If ClientSocket is used directly by netlib, this is OK and doesn't create circular dependency. socketlib must conrain low level classes and functions used by high level netlib and corelib.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now