PDA

View Full Version : Linking Error?


X=YZ
11-26-2003, 03:01 AM
Greetings,

I'm new to Linux and Lf95 on Linux (used the Windows system for years) and having a bit of trouble getting going. Running Redhat Linux 9 (straight off the CD).

I'm getting the error:
[XYZ]$ make
lf95 -g -c Test.f90
Encountered 0 errors, 0 warnings in file Test.f90.
lf95 -g Main.f90
Encountered 0 errors, 0 warnings in file Main.f90.
Main.o(.text+0x3c): In function `MAIN__':
Main.f90:9: undefined reference to `test_module.printit_'
Main.o(.data+0x0):Main.f90:1: undefined reference to `test_module.printit_'
make: *** [doit] Error 1

As you can see, I'm running a simple Makefile:
[XYZ]$ cat Makefile
F90 = lf95
F90_OPTS = -g

doit: Test_MODULE.o
$(F90) $(F90_OPTS) Main.f90


Test_MODULE.o : Test.f90
$(F90) $(F90_OPTS) -c $<

clean:
rm -f *.o *.mod core

The code is similarly simple:

[XYZ]$ cat Test.f90
MODULE Test_Module

CHARACTER(11), PARAMETER :: Messg = 'Hello World'

CONTAINS

SUBROUTINE Printit

write (*,*) Messg

END SUBROUTINE Printit

END MODULE

{XYZ]$ cat Main.f90
PROGRAM Main

USE Test_Module

IMPLICIT NONE

write (*,*) 'Starting'

call printit

write (*,*) 'Ending'

END PROGRAM Main

Any insight that you can provide would be greatly appreciated!

X=YZ

tzeis
12-02-2003, 05:32 PM
Usually, make files do things in two steps or phases: a compilation step and a link step. When you are compiling the main, you are asking lf95 to both compile and link, but you are not telling it to link the object code from the test module. You should either add a "-c" to the compilation command for the main and add a link phase, or put the test object file into the compilation command for the main.