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

linking modules using libraries

dnoack
Beginner
524 Views

Hello,
my example program consist of three different parts. Each part is stored in his own file.
main.f:
program main
call sub
end
sub.f:
subroutine sub
use mod
write(*,*) 'logvar = ', logvar
end
mod.f:
module mod
logical :: logvar = .true.
end module mod

For mod.f I generate a static library as follows
ifort -fpic -c mod.f
ar rc modlib.a mod.o

After that I cleanup the temporary files with
rm mod.o mod.mod

Compiling and linking the entire program aborts withthe error
ifort main.f sub.f modlib.a
fortcom: Error: sub.f, line 2: Error in opening the Library module file. [MOD]
use mod

Please can someone explain to me, what is going wrong.

Thanks,
Dieter

0 Kudos
1 Reply
Steven_L_Intel1
Employee
524 Views
You should not remove the .mod file. The .mod file does not go in the library but must be available to the compiler when you do a USE.
0 Kudos
Reply