[CMake] Auxiliary fortran link libraries?
Brad King
brad.king at kitware.com
Mon Jul 19 11:06:41 EDT 2010
On 07/19/2010 09:37 AM, John Cary wrote:
> So this is very cool.
Thanks!
> Somehow it is not quite working for me. My project is entirely
> C++ with C and C++ libraries
All the magic I just described is for projects that mix Fortran
and C++ themselves. It will not handle this case because the
Fortran language is not even enabled.
> it links to a system lapack and blas that reference the fortran
> libraries, so my final link has the errors,
>
> <start of long link line>
> trilinos/lib/libml.a /contrib/trilinos/lib/libamesos.a
> /contrib/trilinos/lib/libifpack.a /contrib/trilinos/lib/libepetraext.a
> /contrib/trilinos/lib/libgaleri.a /contrib/trilinos/lib/libtriutils.a
> /contrib/trilinos/lib/libepetra.a /contrib/trilinos/lib/libteuchos.a
> /contrib/lapack_cmake-3.2.1-ser/lib/liblapack.a
> /contrib/lapack_cmake-3.2.1-ser/lib/libblas.a -lz
> Undefined symbols:
> "__gfortran_transfer_character", referenced from:
> _xerbla_ in liblapack.a(xerbla.f.o)
Okay, the real problem here is that the lapack and blas static archive
libraries are used without listing their dependencies. In principle
we do not care that their dependencies happen to be the Fortran
runtime libraries. We only want to know "to use lapack, you need to
link to these other libraries over here too". However, in this case
we may need to be aware of Fortran anyway because the symbols in the
lapack and blas libraries provide the Fortran ABI (e.g. mangling).
> I do have
>
> ENABLE_LANGUAGE(Fortran)
> INCLUDE(FortranCInterface)
>
> in my CMakeLists.txt, and it is finding what you say below:
Good. I think you'll need this to get the mangling right so that
you can invoke the Fortran functions from C anyway. FYI, this
assumes that the user will build using the same Fortran compiler
that was used to build lapack and blas. See below.
> numbersix.cary$ grep IMPLICIT CMakeFiles/CMakeFortranCompiler.cmake
> SET(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES "gfortran")
> SET(CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES
> "/usr/local/lib/gcc/x86_64-apple-darwin10/4.5.0;/usr/local/lib")
>
> So is my problem that my project actually has no .{F,F90} files
> that are compiled?
Yes, this is why CMake does not list the libraries. It has no idea
that the link will involve Fortran.
> Can I force the addition of these libraries without referencing
> them explicitly?
One workaround is to list a dummy .F file just to tell CMake that
Fortran will be involved at link time. I call it a workaround
because we are not really giving CMake enough information to
solve this problem for us.
What provides the lapack and blas libraries you're using? How
are we as users supposed to know that they are Fortran-built
libraries and not something provided by a project like CLAPACK.
How do we know what Fortran compiler was used to build them
(to know what mangling it uses)? If information like this is
not available through some automatically detectable means then
any solution will involve manual interference.
-Brad
More information about the CMake
mailing list