[CMake] Linking error after having found a package

Chuck Atkins chuck.atkins at kitware.com
Thu Jul 23 08:36:35 EDT 2015


Hi Cedric,

FIND_PACKAGE(BLAS)
> FIND_PACKAGE(LAPACK)
>
> # I should test with BLAS_FOUND and LAPACK_FOUND here but that's not the
> problem
>

If they're actually required then you can skip the additional check by
calling:

FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)

This will cause the configure step to fail if not found


LIST(GET BLAS_LIBRARIES 0 BLAS_LIB)
> LIST(GET LAPACK_LIBRARIES 0 LAPACK_LIB)
>
...
> As explained in FindBLAS.cmake and Find.LAPACK.cmake, BLAS_LIBRARIES and
> LAPACK_LIBRARIES are lists containing paths to these libraries.
> I get the first entry in each of these lists and try to link with these
> entries (/usr/lib/libf77blas.so, /usr/lib/liblapack.so).
>

You really should be using the _LIBRARIES variables instead it contains the
link dependencies as well.  For shared libraries, this is less of an issue
since the dependencies  will transitively propogate accordingly, but if you
want to link it statically, then you'll need those extra libraries.
Basically, the FOO_LIBRARIES variable should be used as is, if possible,
for FIND_PACKAGE(FOO)


TARGET_LINK_LIBRARY(myexe ${LAPACK_LIB}$ ${BLAS_LIB}$)
>

As Eric already pointed out, the extra trailing "$" needs to go

- Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150723/1b2f7b18/attachment.html>


More information about the CMake mailing list