Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all!
i am new to fortran and I'm using a module that contains a subroutine, that I need to call in another main file, however I am getting some errors and the subroutine is not printing what I want her to print.
Here is my module:
FORTRAN
module prestel
use Constants                                                                   
implicit none                                                                              
contains
  subroutine gradient_density(rho,N,dr,gradiant_rho)
    implicit none
    real(kind=dp), allocatable  :: rho(:) !array for volume density
    real(kind=dp),allocatable   :: gradiant_rho(:)
    integer,intent(in)          :: N
    real(kind=dp),intent(in)    :: dr
    integer                     :: i

    do i = 1,N
      gradiant_rho(i) = (rho(i+1) - rho(i))/dr
    end do
    print *,gradiant_rho
  end subroutine gradient_density
end module prestel

and this is my main file:
FORTRAN
program pt1
  use prestel
  implicit NONE
  ! Declare input/output variables
  integer                    :: Npts=100
  real(kind=dp), allocatable :: gradro(:)
  real(kind=dp), allocatable :: v_density(:)
  real(kind=dp)              :: rho_0 = 10**17
  integer :: i,j
  real (kind=dp) :: c = 2
allocate(gradro(N),v_density(N))
do i = 1,Npts
    v_density(i) = rho_0
  end do
call gradient_density(v_density,Npts,c,gradro)
deallocate(gradro,v_density)
end program tp1

When compiling my module I get this:
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Then, I'm getting this error while compiling my main file:
Undefined symbols for architecture x86_64:
  "___prestel_MOD_gradient_density", referenced from:
      _MAIN__ in cc5vaf5l.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status


What I have tried:

I doubled checked my subroutine but i really can't seem to find what's the problem.
Any idea how to solve this?
Thanks in advance!
Posted
Comments
Richard MacCutchan 4-Feb-21 5:11am    
I do not know what compiler or build system you are using but you need to tell the system how the two source files connect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900