- #1
sketos
- 56
- 0
Hello,
I want to create one file test.f95 where i can keep all my subroutines and use them whenever i create a new program
new.f95.
Is the modules the right way to do it?? because when i create a file let's say test.f95 with the module and one other with my main program (new.f95) when i compile test.f95 i get this :
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
And if i try to compile my main program (new.f95) i get this:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
My programs are:
test.f95 ::
module module1
integer:: n
contains
recursive subroutine sub1(x)
integer,intent(inout):: x
integer:: y
y = 0
if (x < n) then
x = x + 1
y = x**2
print *, 'x = ', x,', y = ', y
call sub1(x)
print *, 'x = ', x,', y = ', y
end if
end subroutine sub1
end module module1
new.f95 ::
program main
use module1
integer:: x = 0
print *, 'Enter number of repeats'
read (*,*) n
call sub1(x)
end program main
I want to create one file test.f95 where i can keep all my subroutines and use them whenever i create a new program
new.f95.
Is the modules the right way to do it?? because when i create a file let's say test.f95 with the module and one other with my main program (new.f95) when i compile test.f95 i get this :
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
And if i try to compile my main program (new.f95) i get this:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
My programs are:
test.f95 ::
module module1
integer:: n
contains
recursive subroutine sub1(x)
integer,intent(inout):: x
integer:: y
y = 0
if (x < n) then
x = x + 1
y = x**2
print *, 'x = ', x,', y = ', y
call sub1(x)
print *, 'x = ', x,', y = ', y
end if
end subroutine sub1
end module module1
new.f95 ::
program main
use module1
integer:: x = 0
print *, 'Enter number of repeats'
read (*,*) n
call sub1(x)
end program main