# Compiling gfortran in Macbook (M4 Pro)

**URL:** <https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373>\
**Category:** Help\
**Created:** [August 31, 2025, 12:11pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373 "2025-08-31T12:11:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fish830911](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fish830911/32/2221_2.png) [@fish830911](https://fortran-lang.discourse.group/u/fish830911)\
**Post date:** [August 31, 2025, 12:11pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/1 "2025-08-31T12:11:23Z")

</div>

Dear Fortran community,

I recently bought a Macbook pro with M4 Pro chips and trying to compile my project with fpm and gfortran. I used to compile on Linux system.

My rsp file for fpm is:

```auto
options run
options --compiler gfortran
options --flag “-O3 -march=native -mtune=native -pipe -fopenmp -flto -Wall -pedantic -g -llapack -lblas -lm”

```

With these flags, gfortran will generate the following error:

```auto
f951: Error: unknown value 'apple-m1' for '-march'
f951: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8.9-a armv8-r armv9-a arm
v9.1-a armv9.2-a armv9.3-a armv9.4-a armv9.5-a native
f951: note: did you mean '-mcpu=apple-m1'?
clang: error: unsupported argument 'apple-m1' to option '-march='

```

I follow the error and change my rsp file to the following:

```auto
options run
options --compiler gfortran
options --flag "-O3 -mcpu=apple-m1 -mtune=native -pipe -fopenmp -flto -Wall -pedantic -g -llapack -lblas -lm"

```

And what’s happening is that all the files are compiled except for the topmost file. So I abort by pressing `Ctrl-c`, and the following error will occur:

```auto
warning: DWARF unit at offset 0x00000000 contains invalid abbreviation 105 at offset 0x000002fd, valid abbreviations are 1-70

```

What’s even weirder (or this is totally normal?) is that if I just run the fpm again (`fpm run @fast` as the rsp file is `fast.rsp`), the code will be compiled and run.

The same thing happened when I chose the flag as `-mcpu=apple-m3`.

---

<div class="post-metadata">

**Author:** ![fish830911](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fish830911/32/2221_2.png) [@fish830911](https://fortran-lang.discourse.group/u/fish830911)\
**Post date:** [August 31, 2025, 12:12pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/2 "2025-08-31T12:12:42Z")

</div>

Just asked chatgpt about the `DWARF` warning, and seems to get solved.

It is because I had the debug flag `-g` on. If I delete that, then the compile passes and run the code.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [August 31, 2025, 2:09pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/3 "2025-08-31T14:09:36Z")

</div>

FYI, many people with Macs and arm64 hardware use the homebrew package manager to install the gfortran and, more recently, flang fortran compilers.

---

<div class="post-metadata">

**Author:** ![fish830911](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fish830911/32/2221_2.png) [@fish830911](https://fortran-lang.discourse.group/u/fish830911)\
**Post date:** [September 1, 2025, 4:42am UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/4 "2025-09-01T04:42:52Z")

</div>

Yes, I am using homebrew to install (almost) everything on my macos. May I ask what the flang for Fortran compilers is? How’s that compared to gfortran?

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [September 1, 2025, 3:32pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/5 "2025-09-01T15:32:17Z")

</div>

Here is a recent discussion thread about the flang compiler. [First official release of Flang! - #11 by wyphan](https://fortran-lang.discourse.group/t/first-official-release-of-flang/9333/11) I have only recently begun to use it, so I don’t know much about its capabilities. I have noticed that it does not support 80-bit or 128-bit floating point arithmetic, but it does support one of the 16-bit floating point formats.

---

<div class="post-metadata">

**Author:** ![ashe](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@ashe](https://fortran-lang.discourse.group/u/ashe)\
**Post date:** [September 1, 2025, 4:40pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/6 "2025-09-01T16:40:05Z")

</div>

It may depend on the target, but I’m seeing that it supports 80-bit (kind = 10) and both 16-bit (kind = 2 & 3) formats.

> **[Compiler Explorer - Fortran](https://godbolt.org/z/dxanxTqav)**
>
> integer, parameter :: &
> real16 = selected\_real\_kind(3, 4), & ! IEEE half
> bfloat16 = selected\_real\_kind(2, 37), & ! truncated IEEE single
> real32 = selected\_real\_kind(6, 37), & ! IEEE single
> real64 =...

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [September 1, 2025, 4:50pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/7 "2025-09-01T16:50:11Z")

</div>

> [@RonShepard](#):
>
> FYI, many people with Macs and arm64 hardware use the homebrew package manager to install the gfortran and, more recently, flang fortran compilers.

I’ve understood (maybe wongly) that conda is somehow the must-have package manager as of today for everything related to development. On Mac I prefer MacPorts to Homebrew (Homebrew attributing the ownership of /usr/local to a regular user is enough to keep me away…), but Macports has less packages, and they are not updated on a frequent basis. So I am considering to have conda besides MacPorts.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [September 1, 2025, 5:41pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/8 "2025-09-01T17:41:51Z")

</div>

> [@PierU](#):
>
> (Homebrew attributing the ownership of /usr/local to a regular user is enough to keep me away…)

I don’t know why, but on intel hardware they do that. On arm64 hardware, it installs in /opt.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [September 1, 2025, 7:16pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/9 "2025-09-01T19:16:48Z")

</div>

> [@RonShepard](#):
>
> I don’t know why, but on intel hardware they do that. On arm64 hardware, it installs in /opt.

That’s better… But the real pain is the ownership given to the regular user: is it the same when it installs in /opt ?

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [September 1, 2025, 8:09pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/10 "2025-09-01T20:09:38Z")

</div>

I would not know. The Homebrew instructions say that you can install under a user account, but I’ve never done that. I always install software from an admin account, and then run it under a user account. That is the same way I have always installed Apple Xcode software. BTW, speaking of Xcode, you only need the command line tools, not the whole package, for both gfortran and flang. Homebrew will install those automatically if necessary.

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [September 1, 2025, 9:36pm UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/11 "2025-09-01T21:36:14Z")

</div>

When Apple switched from Intel to its own silicon, Homebrew moved from that location to the `/opt` directory —it seems, because of a conflict with the Rosetta compatibility layer.

Because of that, I gave MacPorts a try, but it was sort of a nightmare compared to Homebrew… YMMV.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [September 2, 2025, 1:49am UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/12 "2025-09-02T01:49:44Z")

</div>

> [@jwmwalrus](#):
>
> When Apple switched from Intel to its own silicon, […]

It might have been just a coincidence, but that was about the same time that Apple locked down its / directory for security reasons. For example, the fink package manager switched then from using /sw to /opt/sw. I think intel had already been using /opt, I don’t remember any changes then for them. NAG also uses /opt, but I’m a recent nagfor user, so I don’t know if/when they switched directories.

---

<div class="post-metadata">

**Author:** ![jwmwalrus](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jwmwalrus/32/4483_2.png) [@jwmwalrus](https://fortran-lang.discourse.group/u/jwmwalrus)\
**Post date:** [September 2, 2025, 4:28am UTC](https://fortran-lang.discourse.group/t/compiling-gfortran-in-macbook-m4-pro/10373/13 "2025-09-02T04:28:39Z")

</div>

What I meant was that, at the time (i.e., around Apple M1), you had the option to install Homebrew through Rosetta (for x86-64 binaries), and that one used `/usr/local`. And also native/ARM Homebrew, which used `/opt`.

I remember I tried that route for docker (which was almost unusable under ARM), but it was too slow due to the ISA emulation.
