473,883 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Circular Dependencies Between Libraries

Although circular dependencies are something developers should normally
avoid, unfortunately they are very easy to create accidentally between
classes in a VS project (i.e. circular compile-time dependencies). But
then I started wondering how "easy" it would be to similarly make a
NON-RUNTIME circular dependency between (implicitly linked) DLLs.
Indeed authors like John Lakos, who focus on compile/link-time
dependencies (not run-time), tell us to avoid such circular
dependencies between "packages" (i.e. libraries). But to my surprise,
evidently it isn't possible to create a circular library dependency
even if you try...

Tonight I tried to make a circular dependency by creating two Win32
console DLLs in a new VC++ solution, and attempted to make both have a
(implicit link) dependency on the other. But no matter how I tried, in
the end I always got a linker error about missing symbols - because DLL
'A' needed the type library of DLL 'B', which did not exist yet because
DLL 'B' needed the type library of DLL 'A'. A similar problem occurred
if I made both projects just static libraries (instead of DLLs).

In the end, I concluded that to make the circular dependency I would
need to involve some kind of externalized interface descriptions - such
as IDL (e.g. CORBA?). But if I used IDL in that fashion, I figure I
would end up with something that is more akin to circular runtime
dependency rather than a non-runtime dependency (and even then, it may
no longer qualify as truly circular).

Can anyone give me an example of how DLLs (or even static LIBs) can get
involved in a circular dependency? I'm scrutinizing this topic because
authors like Robert Martin or John Lakos ("Large Scale C++") talk about
how "packages" (aka libraries) should be forced away from cyclical
dependencies. Well, why make all that effort of preaching against
circular package/library dependencies, if its not even possible to make
such circular dependencies in the first place?

Oct 19 '06 #1
7 13532

bar...@axiscode .com wrote:
Although circular dependencies are something developers should normally
avoid, unfortunately they are very easy to create accidentally between
classes in a VS project (i.e. circular compile-time dependencies). But
then I started wondering how "easy" it would be to similarly make a
NON-RUNTIME circular dependency between (implicitly linked) DLLs.
Indeed authors like John Lakos, who focus on compile/link-time
dependencies (not run-time), tell us to avoid such circular
dependencies between "packages" (i.e. libraries). But to my surprise,
evidently it isn't possible to create a circular library dependency
even if you try...

Tonight I tried to make a circular dependency by creating two Win32
console DLLs in a new VC++ solution, and attempted to make both have a
(implicit link) dependency on the other. But no matter how I tried, in
the end I always got a linker error about missing symbols - because DLL
'A' needed the type library of DLL 'B', which did not exist yet because
DLL 'B' needed the type library of DLL 'A'. A similar problem occurred
if I made both projects just static libraries (instead of DLLs).

In the end, I concluded that to make the circular dependency I would
need to involve some kind of externalized interface descriptions - such
as IDL (e.g. CORBA?). But if I used IDL in that fashion, I figure I
would end up with something that is more akin to circular runtime
dependency rather than a non-runtime dependency (and even then, it may
no longer qualify as truly circular).

Can anyone give me an example of how DLLs (or even static LIBs) can get
involved in a circular dependency? I'm scrutinizing this topic because
authors like Robert Martin or John Lakos ("Large Scale C++") talk about
how "packages" (aka libraries) should be forced away from cyclical
dependencies. Well, why make all that effort of preaching against
circular package/library dependencies, if its not even possible to make
such circular dependencies in the first place?
VC++, Windows programming, IDL, DLLs are all off-topic here. However,
if you can formulate your question as a pure C++ question
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
then you should get some help. Alternatively, if your question is
specific to Windows, try asking in one of the Windows programming
groups suggested in FAQ 5.9.

Gavin Deane

Oct 19 '06 #2
* ba****@axiscode .com:
>
Can anyone give me an example of how DLLs (or even static LIBs) can get
involved in a circular dependency? I'm scrutinizing this topic because
authors like Robert Martin or John Lakos ("Large Scale C++") talk about
how "packages" (aka libraries) should be forced away from cyclical
dependencies. Well, why make all that effort of preaching against
circular package/library dependencies, if its not even possible to make
such circular dependencies in the first place?
Circular dependencies are possible (in practice) for all kinds of
modules created in C++.

Start by creating two functions foo and bar that depend on each other:

<file foo.cpp>
void bar();
void foo() { bar(); }
</file foo.cpp>

<file bar.cpp>
void foo();
void bar() { foo(); }
</file bar.cpp>

Now compile these files separately: you have circularly dependent object
files.

Create a static library from each: you have circularly dependent static
libraries.

Create a DLL from each: you have circularly dependent DLLs (of course,
how to create such DLLs is off-topic in this group, which is about the
C++ language, so for specific tool usage ask in appropriate group).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 19 '06 #3
ba****@axiscode .com wrote:
Can anyone give me an example of how DLLs (or even static LIBs) can get
involved in a circular dependency? I'm scrutinizing this topic because
authors like Robert Martin or John Lakos ("Large Scale C++") talk about
how "packages" (aka libraries) should be forced away from cyclical
dependencies. Well, why make all that effort of preaching against
circular package/library dependencies, if its not even possible to make
such circular dependencies in the first place?
Since dynamic libraries are a subject of active interest and
development in the C++ standard, I would say that dynamic libraries are
not entirely off-topic. At any rate this question is easily answered:
It is certainly possible to build mutually dependent libraries. The
trick is simply to build one library against a stub library version of
the other.

Greg

Oct 19 '06 #4

ba****@axiscode .com wrote:
Although circular dependencies are something developers should normally
avoid, unfortunately they are very easy to create accidentally between
classes in a VS project (i.e. circular compile-time dependencies). But
then I started wondering how "easy" it would be to similarly make a
NON-RUNTIME circular dependency between (implicitly linked) DLLs.
Indeed authors like John Lakos, who focus on compile/link-time
dependencies (not run-time), tell us to avoid such circular
dependencies between "packages" (i.e. libraries). But to my surprise,
evidently it isn't possible to create a circular library dependency
even if you try...

Tonight I tried to make a circular dependency by creating two Win32
console DLLs in a new VC++ solution, and attempted to make both have a
(implicit link) dependency on the other. But no matter how I tried, in
the end I always got a linker error about missing symbols - because DLL
'A' needed the type library of DLL 'B', which did not exist yet because
DLL 'B' needed the type library of DLL 'A'. A similar problem occurred
if I made both projects just static libraries (instead of DLLs).

In the end, I concluded that to make the circular dependency I would
need to involve some kind of externalized interface descriptions - such
as IDL (e.g. CORBA?). But if I used IDL in that fashion, I figure I
would end up with something that is more akin to circular runtime
dependency rather than a non-runtime dependency (and even then, it may
no longer qualify as truly circular).

Can anyone give me an example of how DLLs (or even static LIBs) can get
involved in a circular dependency? I'm scrutinizing this topic because
authors like Robert Martin or John Lakos ("Large Scale C++") talk about
how "packages" (aka libraries) should be forced away from cyclical
dependencies. Well, why make all that effort of preaching against
circular package/library dependencies, if its not even possible to make
such circular dependencies in the first place?
We had one where one lib required the header of the other and then
there was a solid dependency the other way. I fixed that one.

We also have some sort of funky cyclic dependency solved by compiling
one into the exe and loading the other. I'll fix that one eventually.

Oct 19 '06 #5
Start by creating two functions foo and bar that depend on each other:
>
Now compile these files separately: you have circularly dependent object
files.

Create a static library from each: you have circularly dependent static
libraries.
The simplistic version you describe here, isn't possible. As soon as
you try to link either one of these seperate object files, you will get
a linker error. As another poster pointed out, between two libs 'A'
and 'B', you'd have to make some kind of "3rd party" stub library -
such as 'BStub', and have 'A' link against that.

But using that kind of approach hearkens back to using something like
IDL (which, when compiled, produces lib stubs - at least it does in the
case of CORBA). As such, it is actually "difficult" to produce a
circular dependency, people don't "accidental ly" use IDL in scenarios
like this...

Oct 19 '06 #6
<ba****@axiscod e.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
:Start by creating two functions foo and bar that depend on each
other:
: >
: Now compile these files separately: you have circularly dependent
object
: files.
: >
: Create a static library from each: you have circularly dependent
static
: libraries.
:
: The simplistic version you describe here, isn't possible. As soon as
: you try to link either one of these seperate object files, you will
get
: a linker error. As another poster pointed out, between two libs 'A'
: and 'B', you'd have to make some kind of "3rd party" stub library -
: such as 'BStub', and have 'A' link against that.
:
: But using that kind of approach hearkens back to using something like
: IDL (which, when compiled, produces lib stubs - at least it does in
the
: case of CORBA). As such, it is actually "difficult" to produce a
: circular dependency, people don't "accidental ly" use IDL in scenarios
: like this...

What you are facing is just a limitation of the tool chain you are
using (or of your understanding of it).
There is no need for such a thing as IDL or Corba. In your case it
might be enough to comment-out the contents of the function body
of either library to make a first compile. Then uncomment the code,
rebuild that library, and you're done.

Again, as others pointed out, the specifics of how to do this on
the platform you are using are out of topic here.
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Oct 19 '06 #7
* ba****@axiscode .com:
>Start by creating two functions foo and bar that depend on each other:

Now compile these files separately: you have circularly dependent object
files.

Create a static library from each: you have circularly dependent static
libraries.

The simplistic version you describe here, isn't possible.
T:\type con >foo.cpp
void bar();
void foo() { bar(); }
^Z

T:\type con >bar.cpp
void foo();
void bar() { foo(); }
^Z

T:\cl /GX /GR /c foo.cpp bar.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

foo.cpp
bar.cpp
Generating Code...

T:\lib foo.obj /out:foo.lib
Microsoft (R) Library Manager Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
T:\lib bar.obj /out:bar.lib
Microsoft (R) Library Manager Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
T:\dir /b *.lib
bar.lib
foo.lib

T:\type con >main.cpp
void foo();
int main()
{
foo();
}
^Z

T:\cl /GX /GR main.cpp foo.lib bar.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

/out:main.exe
main.obj
foo.lib
bar.lib

T:\dir /b *.exe
main.exe

T:\_
As soon as
you try to link either one of these seperate object files, you will get
a linker error.
Will I?

As another poster pointed out, between two libs 'A'
and 'B', you'd have to make some kind of "3rd party" stub library -
such as 'BStub', and have 'A' link against that.
Do I really have to?

But using that kind of approach hearkens back to using something like
IDL (which, when compiled, produces lib stubs - at least it does in the
case of CORBA). As such, it is actually "difficult" to produce a
circular dependency, people don't "accidental ly" use IDL in scenarios
like this...
Sorry, that's techo-babble.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 19 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
5266
by: jinal jhaveri | last post by:
Hi All, I have one question regarding circular inheritance I have 3 files 1) A.py , having module A and some other modules 2) B.py having module B and some other modules 3) C.py having module C and some other modules
8
2060
by: Tim Tyler | last post by:
Like C, Python seems to insist I declare functions before calling them - rather than, say, scanning to the end of the current script when it can't immediately find what function I'm referring to. C lets you predeclare functions to allow for the existence of functions with circular dependencies. Does Python allow you to do something similar? If not how do you create functions with circular dependencies in
1
2107
by: Henry Miller | last post by:
I have the following code (much simplified for this post). Note that SessionKey uses DataAccess, and DataAccess requires SessionKey in it's constructor. Public Class SessionKey Public IsValidSession as Boolean Sub New(UserName, Password) ' Create session, including calls on DataAccess ' to validate username/password
2
3108
by: ernesto basc?n pantoja | last post by:
Hi everybody: I'm implementing a general C++ framework and I have a basic question about circular dependencies: I am creating a base class Object, my Object class has a method defined as: virtual String toString(); where String is defined as:
8
4160
by: nyhetsgrupper | last post by:
I have written a windows service and want to expose a web based user interface for this service. I then wrote a class library containing a ..net remoting server. The class library have a method named StartRemotingServer(). To be able to call this method from the windows service I need to reference the remoting class library, but for the class library to be able to access the internal structures of the windows service the class library...
6
17034
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project as "Additional Dependencies" under Linker-Input options. Since those libraries are also in different directory, I specified that library path in project as "Additional Library Directories" under Linker-General options. This is where I see some...
1
1413
by: Anonymous | last post by:
I am working on a suite of existing libraries and I anticipate a future problem. the problem (as i see it), arises as a result of the following: There is a class A that resides in librray A, and class B that resides in library B. class B is declared as ff: class B {
5
3405
by: =?Utf-8?B?Qm9i?= | last post by:
I have a table of dependencies and want to check to see if the dependencies cause a circular reference. Any sugesstions on how to do this using c#. Example, ID DependsOnID 1 2 1 4 2 3 3 1 (circular reference)
6
3479
by: Mosfet | last post by:
Hi, I have two classes, let's call them class A and class B with mutual dependencies as shown below and where implementation is inside .h (no cpp) #include "classB.h" class A {
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10728
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5782
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3227
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.