1

I wish to compile Fortran source code which uses functions from LAPACK and BLAS. When I compile a single source code file e.g.

gfortran -g -framework accelerate test.f

it works.

However, I have many source code files which I want to compile through Makefile. When I modify my Makefile by adding:

LDFLAGS= -framework Accelerate 

(Not sure it is the right way but that's how someone seemed to do it) I get the error that the lapack function used inside is unrecognized.

Can someone tell me what modification to do in the makefile?

Here is the error I get:

gfortran -g test.o  -o a.out
Undefined symbols for architecture x86_64:
  "_sgesv_", referenced from:
     _MAIN__ in test.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [a.out] Error 1

sgesv is the lapack subroutine being called which shall be included in veclib/accelerate framework.

Here is the copy of my Makefile:

#
#              
#
#FFLAGS = -fast
#FFLAGS = gfortran
FC = gfortran
LFLAGS = gfortran -g
LINK = gfortran -g
LDFLAGS = -framework Accelerate
OBJECTS = test.o\

SOURCES = test.f\

a.out:  $(OBJECTS)
    $(LINK) $(OBJECTS) -o a.out

For others:

Here was what I was doing wrong. The last line should change: $(LINK) $(OBJECTS) -o a.out $(LDFLAGS)

Danish Habib
  • 31
  • 1
  • 8

1 Answers1

1

The compiler tells you that it cannot find sgesv, which is (in your case) part of the accelerate framework. From the error message, I see that the command resulting from the Makefile is

gfortran -g test.o  -o a.out

which is missing the linker directive.

So, within the Makefile you are missing the link flags in the actual command:

a.out:  $(OBJECTS)
    $(LINK) $(OBJECTS) -o a.out $(LDFLAGS)
Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68