KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a FORTRAN source code consisting of many different .F and .h files. I need to build an executable from it, but I'm having some problems. The makefile that I produced so far (which may have errors as I'm new to this) is: # compiler FC = /usr/bin/gfortran-4.5 # compile flags FCFLAGS = -g -c -fdefault-real-8 -fbacktrace -fno-align-commons # link flags FLFLAGS = -g -fbacktrace # source files and objects SRCS = $(patsubst %.F, %.o, $(wildcard *.F)) \ $(patsubst %.h, %.mod, $(wildcard *.h)) # program name PROGRAM = blah all: $(PROGRAM) $(PROGRAM): $(SRCS) $(FC) $(FCFLAGS) $@ $< %.o: %.F $(FC) $(FLFLAGS) -o $@ $< %.mod: %.h $(FC) $(FLFLAGS) -o $@ $< clean: rm -f *.o *.mod When I try to make the program, however, I'm getting a slew of undefined reference errors. I mean, every function and subroutine call in the very first compiled .F file gives back an undefined reference error. I thought this was because gfortran was trying to link the files instead of just compiling them and then linking at the end, but I thought the '-c' option was supposed to prevent that. UPDATE: As commenters have pointed out, I mixed up the compile and link flags. Furthermore, you shouldn't compile *.h files. Here is the latest, corrected makefile: # compiler FC = /usr/bin/gfortran-4.4 # compile flags FCFLAGS = -g -c -fdefault-real-8 -fbacktrace -fno-align-commons -fbounds-check -std=legacy # link flags FLFLAGS = # source files and objects SRCS = $(patsubst %.F, %.o, $(wildcard *.F)) # program name PROGRAM = blah all: $(PROGRAM) $(PROGRAM): $(SRCS) $(FC) $(FLFLAGS) -o $@ $< %.o: %.F $(FC) $(FCFLAGS) -o $@ $< clean: rm -f *.o *.mod Now when I run make, it will compile each *.F file in the code, but it fails at the linking stage. I get a bunch of undefined reference errors in the very first *.F file. The compiler seems to
Tags (comma-separated)
Save Edits
Cancel