URGENT Circular dependency problem

Ok, I have two libraries:

corelib
netlib

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?
LVL 3
bjqrnAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
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.
0
 
bjqrnAuthor Commented:
Could you explain the "new library" part a bit further?
0
 
AlexFMCommented:
ClientSocket class must be moved to new library. Create new library project and move this class to it. Let's call it socketlib.
Dependency:
netlib calls InterpretCommand from corelib
corelib calls ClientSocket from socketlib.

References:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.