[CMake] Does find_library check that a found library does in fact link?

Michael Wild themiwi at gmail.com
Wed Sep 28 02:47:28 EDT 2011


On 09/28/2011 07:47 AM, Clifford Yapp wrote:
> 
> 
> On Wed, Sep 28, 2011 at 12:13 AM, Michael Wild <themiwi at gmail.com
> <mailto:themiwi at gmail.com>> wrote:
> 
>     On 09/28/2011 02:44 AM, Clifford Yapp wrote:
>     > I've run into a situation where find_library is returning a symlink:
>     >
>     > /usr/lib/libblah.so -> libblah.so.1
>     >
>     >  but libblah.so.1 does not actually exist (e.g. the symlink is bad).
>     >
>     > Is there an option I can set to have find_library ensure that a found
>     > library file is valid and links?
>     >
>     > Cheers,
>     > CY
>     >
> 
>     Yes, but you need to do it yourself, e.g. use the CheckFunctionExists
>     module.
> 
>     Michael
> 
> 
> Urm.  That's surprising, and not so hot in that it leads to "false
> positives" in find_library reports.  Has anyone wrapped find_library
> with a generic linking test successfully?
> 
> CY

Only if your installation is broken ;-) If the symlink is broken, I
consider this to be a user-error. Period. OTOH, CMake /could/ check
whether the library is a symlink, and if it is, check that it is valid.

But how do you test whether a library is "linkable"? Specifically, I'm
thinking about static libraries. First, only referenced symbols are
linked, so that's kind of difficult to handle as CMake would need to
know at least one symbol name to force the library to be linked at all,
secondly static libraries may have transitive dependencies which CMake
doesn't know about, so it's not possible to link an executable. On Unix
you could create a shared library for the link test, but that depends on
the linker flags being used, and on Windows you can't, since DLL's may
not contain unresolved symbols.

I don't think that there is any good way to handle this in find_library().

Michael


More information about the CMake mailing list