[CMake] lib dependencies

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Apr 26 13:25:23 EDT 2007


On 2007-04-26 12:40+0200 Pascal Fleury wrote:

> Hi guys,
>
> It is my understanding that when an application links to a shared lib, it
> should not have to link to any of the dependencies of that shared lib, as
> this info is included in the *.so or *.dll.

I don't know about windows, but this statement is not correct for all Unix
systems.  Some Unix platform linkers demand all indirect dependencies (i.e.,
dependendies of libraries that your application depends on) be mentioned
when linking your application while others do not.  Autotools wobbled a few
times on this question even for Linux depending on their historical
assessment of the quality of the native Linux linking and loading tools.
Last time I looked, they did not use the indirect dependencies for linking
on Linux.  On the other hand, pkg-config always provides the full list
(assuming the chain of library dependencies is all handled by pkg-config).
Further confusion about these issues exist because people forget that some
libraries/applications will have _both_ direct and indirect dependencies on
other libraries.

The rule that works for me with CMake is to link an application or library
with all direct and indirect dependencies to _external_ libraries (i.e.,
those not being built as part of the CMake build of your software package)
mentioned explicitly. However, to link an application with dependencies to
_internal_ libraries (i.e., those being built as part of the CMake build of
your software package) only the direct dependencies need to be mentioned;
CMake takes care of the indirect internal dependencies in a manner that
seems to work on all platforms we have tried.

I have not answered your additional questions, but I hope this background
information on how to handle direct and indirect library depenendencies
with CMake will be a help to you.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list