I am trying to link against the BLAS and LAPACK libraries using the makefile
FFLAGS = -O0 -fcheck=all -ffree-line-length-none
PROJECTDIR = .
srcdir = $(PROJECTDIR)/src
debug:
gfortran -c $(FFLAGS) $(srcdir)/foo.f90
gfortran -c $(FFLAGS) $(srcdir)/bar.f90
gfortran -c $(FFLAGS) $(srcdir)/foobar.f90
gfortran -o debug *.o -lblas -llapack
rm -f *.o *.mod
When I run make I get that ld: library not found for -lblas
. I ran brew info openblas
and saw that
openblas is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS in Accelerate.framework.
For compilers to find openblas you may need to set:
export LDFLAGS="-L/usr/local/opt/openblas/lib"
export CPPFLAGS="-I/usr/local/opt/openblas/include"
So, I modified (also based on this post) the makefile to include the LDFLAGS
FFLAGS = -O0 -fcheck=all -ffree-line-length-none
LDFLAGS= -L/usr/local/opt/lapack/lib -llapack -L/usr/local/opt/openblas/lib -lblas
debug:
gfortran -c $(FFLAGS) $(srcdir)/foo.f90
gfortran -c $(FFLAGS) $(srcdir)/bar.f90
gfortran -c $(FFLAGS) $(srcdir)/foobar.f90
gfortran -o debug *.o $(LDFLAGS)
rm -f *.o *.mod
Now I get that ld: library not found for -lSystem
. I also tried using the suggested Accelerate framework by using LDFLAGS = -framework Accelerate
. When I did that I received that ld: framework not found Accelerate
.
Any suggestions for correctly linking these libraries is greatly appreciated.