I am trying to write a wrapper code for a simple "Hello World" program on Fortran, but I keep getting linking conflicts whenever I call a subroutine from another file.
These are the codes I used:
file name: helloworld.f90
module hellomod
public
contains
subroutine printing
print *, 'Hello World!'
return
end subroutine
end module hellomod
program main
use hellomod, only: printing
call printing
end program main
file name: hellowrap.f90
subroutine wrapping
use hellomod, only: printing
call printing
end subroutine wrapping
program hellowrap
implicit none
call wrapping
end program hellowrap
The error I got:
/usr/bin/ld: /tmp/cc5p8TIE.o: in function `wrapping_':
hellowrap.f90:(.text+0x5): undefined reference to `__hellomod_MOD_printing'
collect2: error: ld returned 1 exit status
I am a newbie in Fortran programming, so it would be great if I could know what exactly I might be doing wrong.
P.S: I did go through the other questions which were similar to mine. I tried those fixes, but they simply didn't work. One of the questions I explored was about linking a module, but when I tried to compile them together, I got an error as there are essentially two 'main' functions.
I want to compile these files separately, so this does not work. I do not exactly know if this is exclusively a linking issue.