# Help installing gfortran on MacBook Pro with M1pro

**URL:** <https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456>\
**Category:** Help\
**Created:** [May 14, 2022, 1:57pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456 "2022-05-14T13:57:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 14, 2022, 1:57pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/1 "2022-05-14T13:57:44Z")

</div>

I just got a MacBook Pro with the M1 pro chip. Now I’m trying to install gfortran.

First I installed Xcode from the App Store on my Mac. During the installation it did not ask me anything except whether I wanted to install Rosetta, which I did. I’m not sure if Command Line Tools are installed, but when I type  
xcode-select -p  
it returns  
/Applications/Xcode.app/Contents/Developer

Next I went to [http://hpc.sourceforge.net](http://hpc.sourceforge.net). and clicked on gfortran-11.2-bin.tar.gz (gfortran only). I then went to the Downloads directory on my Mac and typed  
sudo tar -xvf gfortran-11.2-bin.tar -C /.

There appeared to be one error at the beginning of the install,  
x usr/local/: Can’t restore time  
but the rest of the install looked fine and it ended with  
x usr/local/bin/gfortran  
tar: Error exit delayed from previous errors.

I tried to compile a test program but it failed,  
gfortran -o mytest.x mytest.f90  
ld: library not found for -lSystem  
collect2: error: ld returned 1 exit status

I tried re-installing gfortran from Downloads (this time without the period at the end):  
sudo tar -xvf gfortran-11.2-bin.tar -C /

The problem persists. I googled this and found several suggestions but some seem outdated and I am not sure how to proceed. Any suggestions on how to fix this problem and get gfortran running on my M1pro?

---

<div class="post-metadata">

**Author:** ![rouson](https://avatars.discourse-cdn.com/v4/letter/r/ce7236/32.png) [@rouson](https://fortran-lang.discourse.group/u/rouson)\
**Post date:** [May 14, 2022, 3:05pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/2 "2022-05-14T15:05:36Z")

</div>

I recommend installing gfortran via [Homebrew](https://brew.sh/). After installing Homebrew, execute the following command in a terminal window:

brew install gcc

The last time I tried this, it installed version 11.3.0.

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [May 14, 2022, 3:23pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/3 "2022-05-14T15:23:28Z")

</div>

Note conda is also an option:

conda install -c conda-forge gfortran

---

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 14, 2022, 4:46pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/4 "2022-05-14T16:46:25Z")

</div>

Thanks for the suggestions about brew and conda. I expect I’ll install one of these eventually. But in the meantime I have searched a bit and discovered that I do indeed have Command Line Tools. I read that it has been automatically installed ever since Xcode 6.1 (and yesterday I installed 13.3.1). You can see it by going to Xcode - Preferences - Locations, at which point you can see if/where Command Line Tools are installed.

So my problem is not related to Command Line Tools…

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [May 14, 2022, 4:56pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/5 "2022-05-14T16:56:40Z")

</div>

> [@rdryne](#):
>
> ld: library not found for -lSystem

I’ve had same problem with Intel `ifort` compiler. Adding

> -L/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/lib/

option to every compiler invocation has fixed the problem. Surely your path to System library might be different.

---

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 14, 2022, 5:13pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/6 "2022-05-14T17:13:36Z")

</div>

My setup looks different and I can’t figure out what to point to it with -L . If I look inside /Library/Developer/, the only thing I see is a subdirectory called PrivateFrameWorks/

On the other hand, if I open Xcode and go to Xcode - Preferences - Locations, it tells me that the location for Command Line Tools is /Applications/Xcode.app . But don’t see anything that looks relevant in subdirectories of Xcode.app . So I am mystified.

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [May 14, 2022, 9:28pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/7 "2022-05-14T21:28:49Z")

</div>

I’m no expert on MacOS so it was _trial and error_ way to find the fix. The directory given above is a location of (among many others) libSystem.tbd file (not libSystem.dylib as one might guess). Try to find that file in your filesystem, maybe it will work.

---

<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:** [May 14, 2022, 10:01pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/8 "2022-05-14T22:01:15Z")

</div>

In a terminal window while logged in with admin privileges, execute the command

sudo xcode-select --install

to make sure the command line tools are installed. This was necessary with all of the 10.x MacOS versions. I don’t know about the 11.x and 12.x versions, but it is someting to check.

I have ordered a new Mac laptop too, so whatever you get working will be of interest to me when it finally is delivered.

---

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 15, 2022, 2:31am UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/9 "2022-05-15T02:31:25Z")

</div>

Problem solved. Thank you msz59. Following your suggestion I searched for libSystem.tbd and I found it in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib

So I compiled using  
gfortran mytest.f90 -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib

and it worked.

---

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 16, 2022, 12:47pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/10 "2022-05-16T12:47:24Z")

</div>

In retrospect it might have been better to install Homebrew first. I just installed it a moment ago. In the process it downloaded Command Line Tools and put it in /Library/Developer/ . It appears that gfortran expects it there, because now gfortran works without specifying -L .

Xcode is huge (about 12 GB) and it’s possible that I’ll never need anything except Command Line Tools. Also, now I have 2 copies of Command Line Tools. So it might have been better to skip Xcode, install Homebrew, and to use it to install packages like gfortran. I just used it to install gnuplot and it worked perfectly.

---

<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:** [May 17, 2022, 1:55am UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/11 "2022-05-17T01:55:57Z")

</div>

At one time, it was possible to install the Apple/gnu command line tools without installing the full Xcode. However, I don’t think you can do that now. I’m like you, I don’t really need the whole Xcode install, but these days disk space isn’t as precious as it used to be, so I just install it and move on.

---

<div class="post-metadata">

**Author:** ![KjellJorner](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kjelljorner/32/590_2.png) [@KjellJorner](https://fortran-lang.discourse.group/u/KjellJorner)\
**Post date:** [May 17, 2022, 2:13am UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/12 "2022-05-17T02:13:37Z")

</div>

It’s fairly easy but not well advertised by Apple: [Install Xcode Command Line Tools Directly · Mac Install Guide](https://mac.install.guide/commandlinetools/4.html)

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [May 17, 2022, 9:00am UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/13 "2022-05-17T09:00:43Z")

</div>

You can also follow the development of Asahi Linux, and when it fully rolls out you can use gcc on linux on your M1 Mac. Which would probably give you an easier time installing the GCC Fortran compiler in future.

> **[Asahi Linux](https://asahilinux.org/)**
>
> Porting Linux to Apple Silicon

---

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 17, 2022, 1:07pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/14 "2022-05-17T13:07:48Z")

</div>

Since installing gfortran I’ve noticed the following:

(1) In one case I needed to add -fallow-argument-mismatch to get a code to compile with the latest gfortran. This was related to compiling a large code with a subroutine that someone else wrote, that I never use, so I was not worried about coding errors.

(2) I have not done a systematic performance test. But I did run a few minute long job on my 2016 MacBook Pro, and also ran it on my M1pro. This was a serial code with no MPI and no OpenMP. The M1pro executed about 2x faster.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [May 17, 2022, 1:18pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/15 "2022-05-17T13:18:27Z")

</div>

> [@rdryne](#):
>
> I have not done a systematic performance test. But I did run a few minute long job on my 2016 MacBook Pro, and also ran it on my M1pro. This was a serial code with no MPI and no OpenMP. The M1pro executed about 2x faster.

You might be in for an interesting result once you start running multi-threaded code on your M1pro. From several tests I have seen the single core performance of the Apple Arm CPU is great, but does not transfer to multi-thread or multi-process performance. Would be interested to see whether you will arrive at the some conclusion.

---

<div class="post-metadata">

**Author:** ![KjellJorner](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/kjelljorner/32/590_2.png) [@KjellJorner](https://fortran-lang.discourse.group/u/KjellJorner)\
**Post date:** [May 17, 2022, 1:34pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/16 "2022-05-17T13:34:17Z")

</div>

> [@awvwgk](#):
>
> You might be in for an interesting result once you start running multi-threaded code on your M1pro. From several tests I have seen the single core performance of the Apple Arm CPU is great, but does not transfer to multi-thread or multi-process performance. Would be interested to see whether you will arrive at the some conclusion.

Would be interested in your experiences here. My Mac M1 with 8 cores has 4 performance cores and 4 efficiency cores. In my very non-scientific experience it seems that limiting to 4 cores is often beneficial.

---

<div class="post-metadata">

**Author:** ![mhulsen](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@mhulsen](https://fortran-lang.discourse.group/u/mhulsen)\
**Post date:** [May 17, 2022, 3:13pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/17 "2022-05-17T15:13:54Z")

</div>

It depends, I guess. At the moment I do not have access to an M1 machine, but a a while ago I tested my fem code on a M1 Macbook Air. The solvers use BLAS routines a lot (such as DGEMM) and with -framework accelerate the M1 was 2x faster than my Intel Macbook Pro 2020 with OpenBLAS, both without multi-threading. The M1 uses the AMX2 coprocessor and hardly touches the CPU. Each cluster of 4 CPUs has one AMX2, so multithreaded BLAS is not an option with accelerate on an M1, having only 4 high-performance cores. In order to get to a comparable speed on the Intel machine I had to use multti-threaded BLAS with all the four CPUs and the fans making a lot of noise. The Macbook Air doesn’t have a fan and therefore is silent.

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [May 23, 2022, 7:53am UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/18 "2022-05-23T07:53:16Z")

</div>

You just need to install brew first,

> **[Homebrew](https://brew.sh/)**
>
> The Missing Package Manager for macOS (or Linux).

Then in the terminal, type

```auto
brew install gfortran mpich

```

Done.

The latest version on brew is perhaps 11.3.0. There are other more latest version of gfortran, but the brew seems very easy to have mpi installed together with gfortran.

You probably also need to install Make.

I learned from @wiremoons,

> [@Does \`sudo apt install gfortran mpich\` support Apple M1 chip?](https://fortran-lang.discourse.group/t/does-sudo-apt-install-gfortran-mpich-support-apple-m1-chip/2950/2):
>
> Hi @CRquantum I can answer a few of your questions: what is the most easy way to use gfortran + mpi for M1 chip Mac? A lot of Apple computer users (both Apple M1 chip and Intel x86 chip) use [Homebrew](https://brew.sh/) or [MacPorts](https://www.macports.org/) to install and manage packages from the command line on their macOS computers. I have tried both, and currently use Homebrew. Once setup, you can install gfortran with the command: brew install gfortran. I have not used mpich but a quick search with brew info mpich does show it exi…

The Xcode stuff you mentioned is for Intel OneAPI, however Intel OneAPI does not optimize for M1, so the speed of Intel Fortran will be the same as gfortran with `-O0` or at best `-Og`. Also the Python distribution in Intel OneAPI will fail when install on M1 Mac. You need to de-select the Python part if you want to install OneAPI on M1 Mac.

It your code is memory bound, you will see performance gain from M1 chip, since Apple uses HBM which is designed particularly for M1.  
if your code is CPU bound, you perhaps will not see too much performance gain from M1 chip especially if your Intel chip is relatively not too old.

* * *

PS.

However I am not sure if gfortran (or gcc) is fully compatible with M1 chip now. I personally have some code run with the same 11.2.0 gfortran on Linux well and can also run on Windows, but on M1 it can give me segment 11 error. If you have things like below (procedure point to some function) you may encounter compatibility issues.

![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/5/5b32ecf6084304d6b23bcd5af8747a56a8d31d57.png)

---

<div class="post-metadata">

**Author:** ![rdryne](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@rdryne](https://fortran-lang.discourse.group/u/rdryne)\
**Post date:** [May 23, 2022, 7:13pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/19 "2022-05-23T19:13:29Z")

</div>

Thanks CRquantum. I just did  
brew install gfortran mpich  
and it installed without any problems. I recompiled and reran a serial code, and it executed about 25% faster than the version of gfortran that I installed previously without using brew. I will try compiling and running an MPI job later today or tomorrow.

---

<div class="post-metadata">

**Author:** ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)\
**Post date:** [May 23, 2022, 8:58pm UTC](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456/20 "2022-05-23T20:58:11Z")

</div>

gfortran 12 intended to patch at least one of the segfault errors on M1. I do not know if it has happened.

[Next page](https://fortran-lang.discourse.group/t/help-installing-gfortran-on-macbook-pro-with-m1pro/3456.md?page=2)
