I have a main program but I want to use it as a subroutine. Therefore, I defined a subroutine inside it
Program main
contains
subroutine ram_cpl
.
.
.
end subroutine ram_cpl
end program main
I am supposed to link it to an executable exe1 and then use further for some external programs. I get exe1 normally but when I call this subroutine in an external program located in a different directory, I get an error
undefined reference to `ram_cpl'
I think the problem is occurring with the linkage as either I should declare this subroutine as public or the linkage should be done properly.
But I can use the PUBLIC statement only inside a module, I also checked my command line used for linkage but I did not get any clue.
/usr/local/bin/mpif90 -frepack-arrays -O3 -ftree-vectorize -ftree-loop-linear -funroll-loops -w -ffree-form -ffree-line-length-none -frecord-marker=4 -fconvert=big-endian -I.. master.o -o exe2 -L.. ../main.o
where main.o is the compiled program containing the subroutine and master is the another program that calls it. exe2 is the executable I am trying to get.
This command line runs properly with other programs and I also tried to replace the program main with module main but it gave me another error.