[Cmake] Automated library dependencies

Amitha Perera perera at cs.rpi.edu
Tue Jan 21 10:20:05 EST 2003


On Tue 21 Jan 2003, Miller, James V (Research) wrote:
> What does not seem to be happening automatically is the propagation
> of the LINK_DIRECTORIES that were used to build library B into the
> LINK_DIRECTORIES that are needed for library A.  So if library B
> uses an external package, library A will also link to that external
> package but it won't know where to find that external package.

You might call this a "feature". I'll try to explain how it works, and
we can then discuss whether the behaviour should change or not.

Keep in mind that CMake normally keeps full paths to everything. So,
when you say FIND_LIBRARY( FOO_LIB foo /usr/local/lib ), it will set
FOO_LIB=/usr/local/lib/libfoo.so. Notice how the path is embedded in
the library name. Now, this whole path gets propagated to library A,
to use your example. Therefore, library A will have the directory in
which to find foo. Good.

Now suppose you do
  LINK_DIRECTORIES( "/some/system/path" )
  TARGET_LINK_LIBRARIES( B "-ljpeg" )
all that will go forward is "-ljpeg". Therefore, A will not have the
path to find jpeg. However, since it is an external library,
presumably the system is able to find it, and so you *do not* need to
know where it is. (Rather, where it was on the system that compiled A;
it may not be in the same place in some other system.)

If you do
  TARGET_LINK_LIBRARIES( B /some/system/path/libjpeg.so )
then all will be well again. In general, if you use FIND_LIBRARY, this
problem should not arise.

My feeling is that explicitly providing "-ljpeg" on the link line is
specifying a "system" library, and the user is responsible for making
sure it is found. I mean in the sense of a deliverable: you don't know
where on the user's system to find this external library. But I admit
the distinction is rather arbitrary and inconsistent.

>  (I assume this is only a problem when library A is not in a
> subdirectory of library B).

Not really. If A is a subdirectory of B, then A will link fine, but if
some executable outside of these two directories tries to link to A,
you'll probably have the same error.

> Should the LINK_DIRECTORIES also be propagated from library B to
> library A.  It is basically the same argument for why the link
> libraries are propagated from library B to library A.

I think this *can* be done. I'll leave the policy decisions--should it
be, and into which version--to others.

Amitha.



More information about the CMake mailing list