When building OpenBLAS with BUILD_SHARED_LIBS=ON on macOS using the NAG Fortran compiler, the build fails during the shared library link step.
Environment:
- macOS (arm64)
- NAG Fortran 7.2 (nagfor)
- CMake with Unix Makefiles or Ninja
Error:
Error: Unrecognised option: -x
Consistent usage: nagfor [options] file ... [-o output]
or similar, because CMake's Fortran shared library link rule on Apple includes -x f95-cpp-input, which is a GCC-specific flag that NAG does not support.
Root cause:
In CMakeLists.txt, the if(APPLE AND BUILD_STATIC_LIBS) block sets CMAKE_Fortran_CREATE_SHARED_LIBRARY to a two-step GCC-specific command:
"sh -c 'echo \"\" | ${CMAKE_Fortran_COMPILER} -o dummy.o -c -x f95-cpp-input - '"
"sh -c '${CMAKE_Fortran_COMPILER} -fpic -shared -Wl,-all_load ...'")
Both steps are GCC-specific:
-x f95-cpp-input is a GCC preprocessing flag; NAG does not support it
-Wl,-shared is a Linux linker flag; macOS requires -dynamiclib
Additionally, CMake's default Fortran shared library rule on Apple also injects -x f95-cpp-input through the link rule template.
I was able to work with Claude to figure out a...kind of ugly fix. I'll make a PR soon.
When building OpenBLAS with
BUILD_SHARED_LIBS=ONon macOS using the NAG Fortran compiler, the build fails during the shared library link step.Environment:
Error:
or similar, because CMake's Fortran shared library link rule on Apple includes
-x f95-cpp-input, which is a GCC-specific flag that NAG does not support.Root cause:
In
CMakeLists.txt, theif(APPLE AND BUILD_STATIC_LIBS)block setsCMAKE_Fortran_CREATE_SHARED_LIBRARYto a two-step GCC-specific command:Both steps are GCC-specific:
-x f95-cpp-inputis a GCC preprocessing flag; NAG does not support it-Wl,-sharedis a Linux linker flag; macOS requires-dynamiclibAdditionally, CMake's default Fortran shared library rule on Apple also injects
-x f95-cpp-inputthrough the link rule template.I was able to work with Claude to figure out a...kind of ugly fix. I'll make a PR soon.