URGENT Circular dependency problem

Posted on 2006-05-22
Last Modified: 2010-04-24
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?
Question by:bjqrn
    LVL 48

    Accepted 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.
    LVL 3

    Author Comment

    Could you explain the "new library" part a bit further?
    LVL 48

    Expert Comment

    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now