0

I have main program Engine.f that calls functions/external in LIB.f. Unlike C++ and Java there is no include in the main program so it will be possible to compile.

How does my Fortran comiler know that there is another library which I use?

I'm using photran from Eclipse.

The MAKE file:

.PHONY: all clean # Change this line if you are using a different Fortran compiler FORTRAN_COMPILER = gfortran all: src/Engine.f $(FORTRAN_COMPILER) -O2 -g \ -o bin/Engine.exe \ src/Engine.f clean: rm -f bin/Engine.exe *.mod 

errors that I get when I compile:

undefined reference to (name of function in **LIB.f**) 

1 Answer 1

1
.PHONY: all clean all: Engine.exe # Change this line if you are using a different Fortran compiler FORTRAN_COMPILER = gfortran FORTRAN_FLAGS=-O2 -g %.o: src/%.f $(FORTRAN_COMPILER) $(FORTRAN_FLAGS) -c $< Engine.exe: Lib.o Engine.o $(FORTRAN_COMPILER) $(FORTRAN_FLAGS) \ -o bin/Engine.exe \ Lib.o Engine.o clean: rm -f *.o *.mod 

In FORTRAN 77, the compiler "just" needs the function to be supplied in a .o file at link time. You can test the Makefile below, it should do what you want.

Modern versions of Fortran use module files to structure libraries, if you ever upgrade to that.

Sign up to request clarification or add additional context in comments.

10 Comments

yes you are Right @pierre de Buyl when I compile it I get this: make all make: Nothing to be done for 'all'. **** This mean it doesn't compile at all. Right?
I forgot to reinstate a make target. Try make Engine.exe
I added a "all" target again
I get this: make all (new line) gfortran "O2 -g" -c src/LIB.f (new line) gfortran: error: O2 -g: No such file or directory (new line) make: *** [Makefile:17: LIB.o] Error 1 (new line) 16:43:01 Build Failed. 1 errors, 0 warnings. (took 360ms) (new line) line 17 is: $(FORTRAN_COMPILE ...
I missed a space, and the quotes are wrong. I edited the makefile.
|