I am trying to create a program which will be pretty heavily dependant on BLAS. I have never made an executable that is dependant on static libraries before though. So far I understand that I need to make the BLAS static library using the following:
gfortran -O2 -c *.f
ar cr libblas.a *.o
Apparently after this you can link programs with BLAS using -lblas on command-line.
My make file looks like the following and has just basically been copied from online:
# ======================================================================
# Declarations
# ======================================================================
# The compiler
FCOMP = gfortran
# flags for debugging or for maximum performance, comment as necessary
FCFLAGS = -g -O2
# libraries needed for linking
LDFLAGS = -lblas
# List of executables to be built within the package
PROGRAM = prog_name_here
# List of subroutines to be built within the package
OBJECTS = foo1.f08 foo2.f08 foo3.f08 ....
# "make" builds all
all: $(PROGRAM)
# ======================================================================
# General Rules
# ======================================================================
# General rule for building prog from prog.o; $^ (GNU extension) is
# used in order to list additional object files on which the
# executable depends
%: %.o
$(FCOMP) $(FCFLAGS) -o $@ $^ $(LDFLAGS)
# General rules for building prog.o from prog.f90 or prog.F90; $< is
# used in order to list only the first prerequisite (the source file)
# and not the additional prerequisites such as module or include files
%.o: %.f08
$(FCOMP) $(FCFLAGS) -c $<
%.o: %.F08
$(FCOMP) $(FCFLAGS) -c $<
%.o: %.f90
$(FCOMP) $(FCFLAGS) -c $<
%.o: %.F90
$(FCOMP) $(FCFLAGS) -c $<
# Utility targets
.PHONY: clean veryclean
clean:
rm -f *.o *.mod *.MOD
veryclean: clean
rm -f *~ $(PROGRAMS)
I am clearly linking the libraries incorrectly as I get the error:
gfortran -g -O2 -c Consistency_Check.f08
gfortran -g -O2 -o Consistency_Check Consistency_Check.o -lblas
Undefined symbols for architecture x86_64:
"_direct_find_", referenced from:
_MAIN__ in Consistency_Check.o
"_kernel_correction_", referenced from:
_MAIN__ in Consistency_Check.o
"_output_", referenced from:
_MAIN__ in Consistency_Check.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [Consistency_Check] Error 1
rm Consistency_Check.o
Could someone highlight how to correctly link static libraries?
** EDIT 1 ** I have placed libblas.a in the same directory as the .f08 / makefile on the off chance that this is a relevant point
** EDIT 2 ** I noticed that removing libblas.a from the working directory makes no difference. I get the same error. I don't think it is being called / used by the makefile.
_direct_find_,_kernel_correction_, etc. symbols from BLAS? - Etan ReisnerConsistency_Check.o? - Etan Reisner