FortranCInterface: Detection fails on macOS 11 with Homebrew GCC 10
FortranCInterface_VERIFY isn’t working on my Mac after an OS and compiler updates. I’m running on macOS 11 with gcc-10 from Homebrew and cmake 3.18. Here are some of the relevant errors from stdout:
-- Detecting Fortran/C Interface Failed to compile -- Verifying Fortran/C Compiler Compatibility Failed to compile CMake Warning (dev) at /usr/local/Cellar/cmake/3.18.4/share/cmake/Modules/FortranCInterface.cmake:309 (message): No FortranCInterface mangling known for VerifyFortran Call Stack (most recent call first): /usr/local/Cellar/cmake/3.18.4/share/cmake/Modules/FortranCInterface/Verify/CMakeLists.txt:16 (FortranCInterface_HEADER) This warning is for project developers. Use -Wno-dev to suppress it. -- Verifying Fortran/C Compiler Compatibility - Failed CMake Error at /usr/local/Cellar/cmake/3.18.4/share/cmake/Modules/FortranCInterface.cmake:383 (message): The Fortran compiler: /usr/local/bin/gfortran-10 and the C compiler: /usr/local/bin/gcc-10 failed to compile a simple test project using both languages. The output was: ****** A BUNCH OF STUFF **** /usr/local/bin/gcc-10 -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/VerifyFortranC.dir/main.c.o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o -o VerifyFortranC libVerifyFortran.a -lgfortran -lquadmath -lm ld: warning: ignoring file libVerifyFortran.a, building for macOS-x86_64 but attempting to link with file built for macOS-x86_64 Undefined symbols for architecture x86_64: "_VerifyFortran", referenced from: _main in main.c.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
I did some detective work as saw that the name-mangling was indeed wrong.
$ nm CMakeFiles/FortranCInterface/VerifyC/libVerifyFortran.a VerifyFortran.f.o: 00000000000000d0 r EH_frame1 U __gfortran_st_write U __gfortran_st_write_done U __gfortran_transfer_character_write 0000000000000000 T _verifyfortran_ 0000000000000058 r lC0 00000000000000c8 r lC1 00000000000000b8 r lC2 $ nm CMakeFiles/FortranCInterface/VerifyC/CMakeFiles/VerifyFortranC.dir/main.c.o 0000000000000018 r EH_frame1 U _VerifyC U _VerifyFortran 0000000000000000 T _main $ cat ./CMakeFiles/FortranCInterface/VerifyC/VerifyFortran.h #ifndef FortranCInterface_HEADER_INCLUDED #define FortranCInterface_HEADER_INCLUDED /*--------------------------------------------------------------------------*/ /* Mangle some symbols automatically. */ #endif