Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29407 Discussions

linking subroutines from different directories

roddur
Beginner
766 Views
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;
[cpp]$ cat trial.f90
        call lm(oidxdn,opnu,opold,oqnu,oqold,avw)
        call lm_end(oidxdn,opnu,opold,oqnu,oqold,avw)
        end [/cpp]

is compiling as:
[cpp] $ gfortran  -c trial.f90 -I/home/rudra/Recursion/LMTO-A [/cpp]

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

[cpp]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 [/cpp]

can anyone tell me the wayout?

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

[cpp]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) [/cpp]

and link this to my main as:

[cpp]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 [/cpp]

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)

0 Kudos
3 Replies
Steven_L_Intel1
Employee
766 Views
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.
0 Kudos
roddur
Beginner
766 Views
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?
0 Kudos
Steven_L_Intel1
Employee
766 Views
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.
0 Kudos
Reply