linking subroutines from different directories

linking subroutines from different directories

hello,
I post this problem earlier, You tried to help me, but still i am searching. So i am reposting it in more details.
How can i compile and link a program that uses subroutines in
different directories?
as for simple example;

$ cat trial.f90
        call lm(oidxdn,opnu,opold,oqnu,oqold,avw)
        call lm_end(oidxdn,opnu,opold,oqnu,oqold,avw)
        end 

is compiling as:

 $ gfortran  -c trial.f90 -I/home/rudra/Recursion/LMTO-A 

but when i am trying to create the executable, it says:

gfortran   trial.f90 -L/home/rudra/Recursion/LMTO-A -llm
/tmp/cc2gfNyf.o: In function `MAIN__':
trial.f90:(.text+0x44): undefined reference to `lm_'
collect2: ld returned 1 exit status 

can anyone tell me the wayout?

As a work around, i tried to create a library(static) as

liblm.a:MAIN/lm-lib.f MAIN/lm-lib-end.f $(lmobj)
        $(FC) -c MAIN/lm-lib.f MAIN/lm-lib-end.f $(lmobj)
        ar rcs liblm.a lm-lib.o lm-lib-end.o $(lmobj) 

and link this to my main as:

irun: $(FOBJ)
        $(FC) $(FFLAGS) $(FPAR) -o $@  $(FOBJ) -L/home/rudra/Recursion/LMTO-
A/ -llm
........
........
main.o : main.f90 util.o ldos.o fermi.o band.o dos.o mmat.o hop.o
shared.o param.o kind.o cgreen.o bit_unm.o nis.o
         $(FC) -c $(FFLAGS) $(FPAR) main.f90 -L/home/rudra/Recursion/LMTO-A -
llm 

This one is working fine, only with a problem that even if my library
(liblm.a) is updated, main is not updating via make and i am forced to
make clean; make everytime i compile.
any suggestion?
(This is historical as i am trying to create and use my FIRST library.
So plz. be simple)

4 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Steve Lionel (Intel)

I don't see a use of Intel Fortran here - are you using ifort to build the library and then link with a gfortran-compiled main program? Mixing Fortran compilers is not supported.

Steve

Quoting - Steve Lionel (Intel)
I don't see a use of Intel Fortran here - are you using ifort to build the library and then link with a gfortran-compiled main program? Mixing Fortran compilers is not supported.

but isnt a static library a stand alone; independent of how they are built?

Bild des Benutzers Steve Lionel (Intel)

Quoting - roddur
but isnt a static library a stand alone; independent of how they are built?

Not at all. It has external references to the compiler's language support library and routines may have incompatible calling interfaces. A shared object (.so) can hide most of the support library issues, but even then mixing Fortran compilers is not recommended.

Steve

Melden Sie sich an, um einen Kommentar zu hinterlassen.