views:

40

answers:

1

I'm having trouble trying to compile a simple fortran program which uses a module in the same directory. I have 2 files: test1.f90 which contains the program and modtest.f90 which contains the module.

This is test1.f90:

program test
  use modtest
  implicit none
  print*,a
end program test

This is modtest.f90:

module modtest
  implicit none
  save
  integer :: a = 1
end module modtest

Both files are in the same directory. I compile modtest.f90 and test.f90 like this:

gfortran -c modtest.f90
gfortran -o test1 test1.f90

But then I get this error:

/tmp/cckqu8c3.o: In function `MAIN__':
test1.f90:(.text+0x50): undefined reference to `__modtest_MOD_a'
collect2: ld returned 1 exit status

Is there something I'm missing? Thanks for the help

+1  A: 

does this work

gfortran -o test1 test1.f90 modtest.o
Preet Sangha
Certainly work! =)
kemiisto
Yes it does, thanks! I've been learning Fortran for a month now, I can't believe I didn't know that :P
Eddy