get "undefined reference" with routines contained in a module



Hi,

I have two files, one is a module which *contains* (internal) functions and subroutines, the other is a main program:

file 1:

MODULE mod
[declaration part]
CONTAINS
SUBROUTINE func1()
[code]
END SUBROUTINE func1
END MODULE mod

file 2:

PROGRAM test
USE mod
CALL func1()
END PROGRAM test

If I compile/link both files at the same time, as:

g95 mod.f90 test.f90

I get the expected result, but if I compile the files separately, first

g95 -c mod.f90

and then the main program with

g95 test.f90

I get a "undefined reference" error. My goal is to use modules like libraries in F77 times: Compile modules with internal routines, put the *.mod files into the lib directory (e.g.) and use them with the "-I" option as a library for other main programs. Unfortunately only the declaration part is visible in the separate compiled main program. The contained routine part is not.

Do I have to use interface blocks to reach my goal although I used internal functions/subroutines? BTW: The subroutines don't contain user-defined data types, etc which would need interface blocks.

Do I have to write a single module with the public declaration part and all interface blocks of all (external) functions/subroutines. Write external subroutines/functions with the USE statement of the single module mentioned above. Make a library of these subroutines/functions. Use the USE statement in the main program.

Or maybe I haven't understood the new module architecture of Fortran 90 correctly.


Best regards,

Hani
.



Relevant Pages

  • Re: interface blocks
    ... Lynn McGuire wrote: ... > I have about 3500 subroutines with 400,000 lines of f66/f77 that I am ... interface blocks, and Michael Metcalf has a free program for that does ... both the approriate keyword and the procedure name." ...
    (comp.lang.fortran)
  • Fortran module in a library
    ... I have dozens of subroutines in a module file, ... provide generic names via interface blocks. ... avoid unintentional code changes and subsequent time-consuming ...
    (comp.lang.fortran)
  • Re: Structure of large link libraries in f95
    ... make a module with nothing but interface blocks. ... List the subroutines in one makefile macro and the functions in another, cat each set, change all end statements in each set using sed, cat the two together and INCLUDE the resulting file. ... Make all library files prerequisites. ...
    (comp.lang.fortran)