Problem building cyclic libraries

Hi,

Disclaimer: the names of the types expressed here do not have to make any sense!

I am *not* having trouble compiling libraries that depend on each other, yet I had expected *it would not be possible* to build them due to their mutual dependency.

For instance, Lib1.lib contains a class Point with a method returning a Rectangle by value. This method constructs a rectangle in its body. Yet rectangle is placed in another library Lib2.lib. Rectangle inherits privately from Point and also returns its position in a method that constructs a Point. So we have a cycle.
The problem is that I am not even giving the library names that these 2 libs need to satisfy their implementations (i.e. Rectangle is not being linked with Lib1, and Point is not being linked with Lib2).
Building these libraries works perfectly but where are they getting the code they need?

Thanks,
Juan
Last edited on
If the libraries are static and when you try to link them into a program you link only one, you'll get a linker error.
If the libraries are dynamic it's possible that the program will never link successfully at run time.

Couple questions:
1. What's the point of separating code into two libraries if it's not possible to link a program with just one of them? Why not just have a single library?
2. Why is a Rectangle a kind of Point? Shouldn't a Rectangle contain Points?
Hi helios,

Yes, the names of the classes are not important (they could be called X and Y) and nor is the implied semantics. What I am not understanding is how a .LIB can build correctly when it does not include or link itself to another .LIB that contains the definitions of classes it uses.

That is, one library contains class Point but Point has a member that returns a Rectangle ... Rectangle is defined in the other library but we don't link to it. The librarian should complain that there are undefined components and should not build the .LIB (neither of the two LIBs actually).

This is just an exercise trying to understand static libraries and how they deal with dependent code. It seems to me that the conclusion to be arrived at is that .LIBs do not contain everything they need to be linked and used in an EXE.

Is this conclusion correct?

Regards,
Juan
Is this conclusion correct?
Yes, it doesn't make sense for a library to link. Only the final executable/dll will be linked.
A static library is just a bunch of .objs bundled together without being linked. If there are any linking problems, they'll only show up when it is linked into a DLL or executable.
Topic archived. No new replies allowed.