Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

WRF on Mac?

You certainly can - I have WRF4.5 compiled on my M2 Max. I found the flags needed to be slightly different as there were issues getting both NetCDF libraries to compile properly. Here's what I used for my environment, then you can follow the main compilation tutorial normally:

export DIR=<dir_path_to_libraries>
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export NCDIR=<dir_path_to_libraries>/netcdf
export LDFLAGS=-L$DIR/netcdf/lib
export CPPFLAGS=-I$DIR/netcdf/include
export FCFLAGS="-w -fallow-argument-mismatch -O2"
export FFLAGS="-w -fallow-argument-mismatch -O2"
export PATH=$DIR/netcdf/bin:$PATH
export NETCDF=$DIR/netcdf
export PATH=/opt/homebrew/Cellar/mpich/4.1.2/bin:$PATH
export DYLD_LIBRARY_PATH=${NCDIR}/lib:${LD_LIBRARY_PATH}
export NFDIR=<dir_path_to_libraries>/netcdf

A couple of items to note:

1. Installing MPICH via homebrew was the only way I could bypass some of the Apple Silicon errors for MPI.
2. I had to manually create the grib2 dir for some reason.
3. Replace <dir_path_to_libraries> to the full path to wherever you store your libraries.

Hope it works out!
 
You certainly can - I have WRF4.5 compiled on my M2 Max. I found the flags needed to be slightly different as there were issues getting both NetCDF libraries to compile properly. Here's what I used for my environment, then you can follow the main compilation tutorial normally:



A couple of items to note:

1. Installing MPICH via homebrew was the only way I could bypass some of the Apple Silicon errors for MPI.
2. I had to manually create the grib2 dir for some reason.
3. Replace <dir_path_to_libraries> to the full path to wherever you store your libraries.

Hope it works out!
Code:
brew install wget
    brew install git
    brew install gcc@12
    brew install libtool
    brew install automake
    brew install autoconf
    brew install make
    brew install m4
    brew install java
    brew install ksh
    brew install grads
    brew install ksh
    brew install tcsh

    brew install python@3.10
    brew install cmake
    brew install xorgproto
    brew install xorgrgb
    brew install xauth
    brew install curl
    brew install flex
    brew install byacc
    brew install bison
    brew install gnu-sed

#############################Compilers############################

    #Symlink to avoid clang conflicts with compilers
    #default gcc path /usr/bin/gcc
    #default homebrew path /usr/local/bin
    echo $PASSWD | sudo -S unlink /opt/homebrew/bin/gfortran
    echo $PASSWD | sudo -S unlink /opt/homebrew/bin/gcc
    echo $PASSWD | sudo -S unlink /opt/homebrew/bin/g++

    source ~./bashrc
    gcc --version
    g++ --version
    gfortran --version

    cd /opt/homebrew/bin

    echo $PASSWD | sudo -S ln -sf gcc-12 gcc
    echo $PASSWD | sudo -S ln -sf g++-12 g++
    echo $PASSWD | sudo -S ln -sf gfortran-12 gfortran

    cd
    source ~/.bashrc
    source ~/.bash_profile
    gcc --version
    g++ --version
    gfortran --version

    export CC=gcc
    export CXX=g++
    export FC=gfortran
    export F77=gfortran
    export CFLAGS="-fPIC -fPIE -Wno-implicit-function-declaration -Wall"

another way to do it from my installation codes
 
Hi,
I was trying to install WRFV4.5 in M3pro and getting this error while compiling.

gcc -O0 -c y.tab.c

scan.y:37:12: fatal error: malloc.h: No such file or directory

37 | #include <malloc.h>

| ^~~~~~~~~~

compilation terminated.

make[1]: *** [y.tab.o] Error 1



Please find my zshrc and log file attached.

Thank you.
Musaid
 

Attachments

  • zshrc.txt
    1.3 KB · Views: 5
  • terminal.log
    134.7 KB · Views: 3
Hi,
I was trying to install WRFV4.5 in M3pro and getting this error while compiling.

gcc -O0 -c y.tab.c

scan.y:37:12: fatal error: malloc.h: No such file or directory

37 | #include <malloc.h>

| ^~~~~~~~~~

compilation terminated.

make[1]: *** [y.tab.o] Error 1



Please find my zshrc and log file attached.

Thank you.
Musaid
@musaidpp
@clamalo

That's the mac header issue.

Best thing is to download gcc from homebrew link it to gcc for macos and then it should work.

Alternatively if you look in my signature you can see the scripts I have that might help you work through it too.
 
Thank you William.Hatheway for your response.

I had already downloaded gcc from homebrew and linked it. I think I have messed up with homebrew and macports.
I was using flex and yacc from macports installation. Since libiconv was making some issue, I removed the libiconv from macports installation (/opt/local).
I don't know why, I couldn't find yacc inside homebrew, so I linked bison and now there is a permission issue!!

Please find portion from log showing error :

compile kpp

/opt/homebrew/opt/bison -d scan.y

make[1]: /opt/homebrew/opt/bison: Permission denied

make[1]: *** [y.tab.c] Error 1


I tried sudo ./compile em_real and still not working. Any idea about this?


Thank you,
Musaid
 
Last edited:
Thank you William.Hatheway for your response.

I had already downloaded gcc from homebrew and linked it. I think I have messed up with homebrew and macports.
I was using flex and yacc from macports installation. Since libiconv was making some issue, I removed the libiconv from macports installation (/opt/local).
I don't know why, I couldn't find yacc inside homebrew, so I linked bison and now there is a permission issue!!

Please find portion from log showing error :

compile kpp

/opt/homebrew/opt/bison -d scan.y

make[1]: /opt/homebrew/opt/bison: Permission denied

make[1]: *** [y.tab.c] Error 1


I tried sudo ./compile em_real and still not working. Any idea about this?


Thank you,
Musaid
possible that this is an issue with both macports and homebrew operating on the same system.

If possible can you remove one or the other ( if they aren't needed for other programs) and see if you can install them again?
 
Top