Circular dependency problem

Brian Dessent
Sat Oct 11 13:33:00 GMT 2008

John Emmas wrote:

> functions contained in the other one).  If I was programming in Microsoft
> VC++ I'd normally resolve this by exporting the relevant functions.
> Exporting them (I believe) tells the linker that any unresolved function
> addresses will be resolved at run time (hence, dynamic linking).

That's not how DLLs work.  All references must be defined at link time,
there is no way to defer them to runtime unless you explicitly use
LoadLibrary/GetProcAddress and function pointers.  __declspec(dllexport)
does not change the situation at all.  What you probably meant was that
you (or perhaps the IDE did it for you) created a .def file which lists
the exported functions of a DLL before it actually exists, which can be
used to create an import library for linking.

> I don't know how the equivalent technology works in gcc but whatever it
> involves, the project compiles and links fine on my Linux box.  However,
> I can't make it build with Cygwin.  Both branches compile successfully but
> neither will link because the other one hasn't been built yet.
> Is there anywhere where I can find some information about how to make
> this work?  I could probably make a cut-down version if anyone wants to see
> the problem for themselves.

Create a .def file listing the exported functions of library A, and then
generate an import library from that.  Link library B against the
library A import lib and at the same time create an import library for
B.  Then link library A against that.

$ dlltool -d libA.def -l libA.dll.a
$ gcc -shared $libB_objects -o libB.dll -L. -lA \
$ gcc -shared $libA_objects -o libA.dll -L. -lB


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list