Fortran compilation error - undefined reference
fortran
Solution
If the definition of subroutine read_step is in a module, then you have either forgotten to add the USE statement for that module to the top of the main program, or the relevant procedures in the module are not PUBLIC.
With that compiler (and some others) linker names for module procedures generally consist of the module name followed by 'mp' (case may vary) followed by the procedure name, with various amounts of leading and trailing underscores salted to taste. Your linker error doesn't have any of that "mangling", which indicates that when compiling the scope with the procedure reference, the compiler doesn't think the procedure is a module procedure.
Problem
I am trying to compile a fortran program which uses a bunch of modules. I obtain an error when I compile it, and it's driving me crazy. The error is originated by the addition of one subroutine and takes place when I try to recompile the program: Main program contains these two lines: -- ``` call read_step(nStepOne,molOne) call read_step(nStep,mol) ``` -- This is calling one of the subroutines in a file "fileio.f90": -- ``` subroutine read_step(n,tape) implicit none integer, intent(in) :: tape integer, intent(out) :: n character(len=6) :: dum rewind(tape) read (tape,*) read (tape,*) dum, n rewind(tape) return ! end subroutine read_step ``` -- When I try to compile it, the following error arises: ``` ifort -o SpIdMD.x *.o -static-intel -openmp SpIdMD.o: In function `MAIN__': SpIdMD.f90:(.text+0x3b2): undefined reference to `read_step_' SpIdMD.f90:(.text+0x3c5): undefined reference to `read_step_' make: *** [SpIdMD.x] Error 1 ``` Other calls to subroutines in the same module did not give any error, and I just don't see any difference between the calls to the "old subroutines" and the one I just created. An example of one of these "old subroutines", which does not give any complaint, is: In the main program: ``` call get_dim(n_atom,nSnap,mol) ``` In the fileio.f90: ``` subroutine get_dim(n,n_snap,tape) implicit none integer,intent(in) :: tape integer,intent(out) :: n, n_snap integer :: m rewind(tape) read (tape,*,err=1,end=2) n rewind(tape) m = 0 do while (.true.) read (tape,*,err=1,end=3) m = m +1 end do 3 n_snap = m/(n + 2) if (m.ne.(n_snap*(n + 2))) stop 'unexpected end of input file' rewind(tape) return ! 1 stop 'error in input file' 2 stop 'unexpected end of input file' end subroutine get_dim ``` I have absolutely no idea why this behavior. I'd be grateful if anybody could help me solve this nightmare. Thanks!