Installing flang on macOS

Hi,

I am trying to install flang on macOS, throught the MacPorts utility.

I did first sudo port install flang-19 +openmp as recommended on various sites.

First problem : I can’t use OpenMP:

$ flang-mp-19 conv.f90 testconv.f90 -fopenmp
error: Semantic errors in testconv.f90
./testconv.f90:2:5: error: Cannot read module file for module 'omp_lib': Source file 'omp_lib.mod' was not found
  use omp_lib
      ^^^^^^^
./testconv.f90:27:10: error: No explicit type declared for 'omp_get_wtime'
     tic = omp_get_wtime()
           ^^^^^^^^^^^^^

Linking with OpenMP works, though, it’s just that it can’t find the mod file (and I couldn’t find it either in the installation directories).

Second problem: the executable name is flang-mp-19, not flang. Not a big deal, but would be better with the simpler name. Normally in MacPorts this is managed with a special command to select the default version, which works for gcc or clang: sudo port select --set mp-clang-19. But it has no effect on flang.

Maybe you can find some hints in,

1 Like

Fortran on ARM Macs is a bit of pain… No Intel compiler, gortran and NAG don’t have a debugger, flang installation is rough…

2 Likes

I thought SciPy was already using flang on ARM (with Windows and Mac).

There is a brew bottle for flang already: flang — Homebrew Formulae

$ brew install flang
$ flang-new --version
Homebrew flang-new version 19.1.4
Target: x86_64-apple-darwin23.6.0
Thread model: posix
[...]

Same problem however:

$ flang-new test_omp.f90 
error: Semantic errors in test_omp.f90
./test_omp.f90:1:5: error: Cannot read module file for module 'omp_lib': Source file 'omp_lib.mod' was not found
  use omp_lib
      ^^^^^^^