Skip to content

Shared library build fails on macOS when using NAG Fortran compiler #5823

@mathomp4

Description

@mathomp4

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions