I am trying to compile some Fortran code using intel oneapi compiler (ifort -v 2021.2.0) and linking it with another Fortran library (MultiZ) previously coded. I am using the following makefile:
# User parameters
LIBPATHS = /RouteToLibrary/
LIBFLAGS = -lmultiz
# Options. 1: use gfortran. 2: use ifort.
OP = 2
# Fortran compilers
# GFC: GNU Fortran Compiler
# IFC: Intel Fortran Compiler
GFC = gfortran
IFC = ifort
# Common flags
# -g: Produce symbolic debug information.
# -c: Compile to object (.o) only, do not link.
# -pg: Profile with gprof
DEBUG = -g
FCFLAGS = -c $(DEBUG) -pg
FLFLAGS =
# GNU Fortran Flags
GFCFLAGS = -fdefault-real-8 -fdefault-double-8 -Wall -pedantic -std=f2008
GFLFLAGS =
# Intel Fortran Flags
# IFCFLAGS = -autodouble -warn
IFCFLAGS = -warn
IFLFLAGS =
# Lists and variables
ifeq ($(OP),1)
FC := $(GFC)
FCFLAGS := $(FCFLAGS) $(GFCFLAGS)
FLFLAGS := $(FLFLAGS) $(GFLFLAGS)
else
FC := $(IFC)
FCFLAGS := $(FCFLAGS) $(IFCFLAGS)
FLFLAGS := $(FLFLAGS) $(IFLFLAGS)
endif
# List of example files, objects and executables.
FILES := $(wildcard *.f90)
OBJS := $(patsubst %.f90, %.o, $(FILES))
EXEC := $(patsubst %.f90, %.exe, $(FILES))
# List of filenames without extension.
NOEX := $(subst .f90,,$(FILES))
LPATHS := $(foreach PATH, $(LIBPATHS), -L$(realpath $(PATH)))
IPATHS := $(foreach PATH, $(LIBPATHS), -I$(realpath $(PATH)))
define MAKE_EXE
$1.exe : $1.o ; $(FC) $(FLFLAGS) $(LPATHS) $1.o $(LIBFLAGS) -o $1.exe
endef
# Rules.
all : $(EXEC)
$(foreach f, $(NOEX), $(eval $(call MAKE_EXE, $f)))
%.o : %.f90
$(FC) $(FCFLAGS) $(IPATHS) $< -o $@
clean :
rm -f $(EXEC) $(OBJS)
However, I am getting the following error message:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
MyMainScript.o: In function `MyFunction_':
And after some warning messages, the following error message is displayed:
collect2: error: ld returned 1 exit status
make: *** [MyMainScript] Error 1