FortranCInterface: Detection broken by CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY
I'm trying to compile LAPACK in Yocto Linux targeting an ARM64 platform. LAPACK uses CMake and calls the VerifyFortran check, which fails to link with the aarch64
gcc
with the following error:
/usr/share/cmake-3.14/Modules/FortranCInterface/Verify/main.c:14: undefined reference to `VerifyFortran'
Using nm
on the libVerifyFortran.a
object shows
VerifyFortran.f.o:
U _gfortran_st_write
U _gfortran_st_write_done
U _gfortran_transfer_character_write
U __stack_chk_fail
U __stack_chk_guard
0000000000000000 T verifyfortran
My suspicion was that it was failing to link due to a case mismatch (Fortran is notoriously case insensitive). Sure enough, after I modified the libVerifyFortran.a
file in a hex editor to change verifyfortran
to VerifyFortran
, it links just fine.
I have no idea why other people aren't having the same issue (if they were, I assume it would have been fixed by now). Perhaps it's a weird artifact of the aarch64
implementation of gcc
. I have searched and searched for a way to make the gfortran
compiler preserve the casing in its symbol files from its source files, but haven't been able to find anything. As far as I can tell right now, it's not possible.
Another possible solution to this would be to use all lower case symbol names in the CMake C source files which are intended to link against Fortran, i.e. update Modules/FortranCInterface/Verify/main.c
to use verifyfortran()
instead of VerifyFortran()
.
Anyway, is there a known solution to this problem?