You are currently viewing Install GCC-12/G++-12 on macOS Apple M1

Install GCC-12/G++-12 on macOS Apple M1

Apple began the transition from Intel processors to Apple silicon (i.e., Apple M1 ARM64) in Mac computers [1]. Thus, the 15-year partnership with Intel is about to be ended [2].

In the other side, Intel introduced Intel oneAPI – an unified and cross-architecture performance programming model [3], without supporting new Apple chips. This challenges developers who need to use Intel Fortran Compiler [4] which only supports products using Intel processors.

A solution just come!

GNU Compiler Collection GCC 12.1 was released on May 6, 2022 [5] that support Fortran compilers on AArch64 (i.e., ARM64) architectures.

How to install GCC 12.1 on macOS M1?

gcc, g++

Open Terminal and check gcc --version, returns clang compiler only.

Install Homebrew, see instruction here.

Check brew version: brew --version.

Install GCC 12.1: brew install gcc@12.

Check GCC 12.1 installation: gcc-12 --version.

Go to its install location: cd /opt/homebrew/bin.

Make soft/symbolic links: ln -s gcc-12 gcc and ln -s g++-12 g++.

Check the gcc and g++ priorities and location: where gcc.

Exit and reinitiate the terminal, type in gcc --version returns the GCC 12.1 version through Homebrew installation.

gfortran-12

Check the version of gfortran: gfortran --version, still point to old version gfortran-11 within gcc-11.

Go to its install location: cd /opt/homebrew/bin.

Make soft/symbolic links: ln -sf gfortran-12 gfortran. The -f option remove existing destination files (if any) before creating the link [6].

References:

[1]  https://support.apple.com/en-us/HT211814
[2]  https://www.cnbc.com/2020/11/10/why-apple-is-breaking-a-15-year-partnership-with-intel-on-its-macs-.html
[3]  https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview.html
[4]  https://www.intel.com/content/www/us/en/developer/tools/oneapi/fortran-compiler.html
[5]  https://gcc.gnu.org/gcc-12/
[6] https://unix.stackexchange.com/questions/207294/create-symlink-overwrite-if-one-exists

This Post Has 3 Comments

  1. Chuck

    I encountered a problem after the installation in compiling my program antsim.c:
    In file included from antsim.c:4:
    /opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/current/gcc/aarch64-apple-darwin22/12/include-fixed/stdio.h:78:10: fatal error: _stdio.h: No such file or directory
    78 | #include
    | ^~~~~~~~~~
    compilation terminated.
    chuckh@Windom2 Simulation Automation % echo $PATH
    /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Little Snitch.app/Contents/Components:/Library/Apple/usr/bin

    What should I do?

    Thanks,
    Chuck

  2. vedant

    ln -s gcc-12 gcc
    ln -s g++-12 g++

    when I am entering these commands it say file exists what should I do now??

  3. ekthelionn

    what does this step mean: Check the gcc and g++ priorities and location: where gcc.?

Leave a Reply