我正在尝试编译Fortran 90程序并为此准备一个Makefile。我想链接到netCDF库(openSUSE 15提供的库)。
我试图改编一个已经可用的Makefile。这些是我的Makefile中的相关行:
FC = gfortran
ROOTDIR = /media/work/codes/fortran
SRCDIR = $(ROOTDIR)/src
BLDDIR = $(ROOTDIR)
EXEDIR = $(ROOTDIR)
FPROGS = ascii2nc
NC_C_DIR = /usr/lib/hpc/gnu7/openmpi3/netcdf/4.6.1
NC_FORT_DIR = /usr/lib/hpc/gnu7/openmpi3/netcdf-fortran/4.4.4
NC_FORT_INC = $(NC_FORT_DIR)/include # netCDF's netcdf.mod file
NCINC = $(NC_FORT_INC)
NC_C_LIB = $(NC_C_DIR)/lib64
NC_FORT_LIB = $(NC_FORT_DIR)/lib64
NCLIB = -L$(NC_FORT_LIB) -L$(NC_C_LIB) -lnetcdff -lnetcdf
INCLUDES = -I$(NCINC) -I$(FFTINC)
FOPTS = -Wall -O2 #-fno-range-check
FFLAGS = $(FOPTS) $(INCLUDES)
LFLAGS = $(NCLIB) $(FFTLIB)
VPATH = $(shell cat $(BLDDIR)/Filepath) # 'Filepath' is same as $(SRCDIR)
all: $(FPROGS)
DEPS = depends # Contains list of dependencies
# This writes all dependencies on 'depends'
$(BLDDIR)/$(DEPS): $(BLDDIR)/Srcfiles $(BLDDIR)/Filepath
$(BLDDIR)/mkDepends Filepath Srcfiles > $@
# This writes all F90 files on 'Srcfiles'
$(BLDDIR)/Srcfiles: $(BLDDIR)/Filepath
$(BLDDIR)/mkSrcfiles > $@
an_objs = ascii2nc.o shr_vars.o nc_mod.o nl_read.o shr_kind_mod.o \
grid_gen.o endrun.o
ascii2nc: $(an_objs)
$(FC) -o $@ $(an_objs) $(FFLAGS) $(LFLAGS)
.SUFFIXES:
.SUFFIXES: .F90 .o
.F90.o:
$(FC) -c $(FFLAGS) $(LFLAGS) $<
include $(BLDDIR)/$(DEPS)
我得到的错误是:
gfortran -o ascii2nc ascii2nc.o shr_vars.o nc_mod.o nl_read.o shr_kind_mod.o grid_gen.o endrun.o -Wall -O2 -I / usr / lib / hp / grc7 / openmpi3 / netcdf-fortran / 4.4 .4 / include -I -L-/ usr / lib / hpc / gnu7 / openmpi3 / netcdf-fortran / 4.4.4 / lib64 -L / usr / lib / hpc / gnu7 / openmpi3 / netcdf / 4.6.1 / lib64 -lnetcdff -lnetcdf -lfftw3 /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld:找不到-lnetcdff collect2:错误:ld返回1退出状态 make:*** [Makefile:128:ascii2nc]错误1
有人可以帮忙吗?
谢谢。