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

library and module

roddur
Beginner
1,669 Views
dear friends,
i have created a library file made up of subroutines(as usual) and they are created using module. is it possible to USE these module from other directories? actually i have to call to subroutines from that library (say A and B), and B's result depends on output of A. so in the argument list of A and B i should put them, waht i generally do using explicit interface. but as in this case, modules are in different directories, i cant simply use them. what is the way out?

i am compiling the main code with the libraries using simple command:
[cpp]irun: $(FOBJ)
	$(FC) -o $@ $(FFLAGS) $(FPAR) $(FOBJ) ~/Recursion/LMA/liblm.a [/cpp]

is this ok? i can see it is compiling and running, but not something i learned in manuals.
0 Kudos
10 Replies
Steven_L_Intel1
Employee
1,669 Views
USE looks at the include path to find the compiled module files (.mod), so you'll need a -I in there to specify the path to the modules.
0 Kudos
roddur
Beginner
1,669 Views
USE looks at the include path to find the compiled module files (.mod), so you'll need a -I in there to specify the path to the modules.
[cpp]main.o : main.f90 ~/Recursion/LMA/liblm.a -l/home/rudra/Recursion/LMA/mlms.mod
[/cpp]
while compiling using -l, i get the error:

make: stat: lib/home/rudra/Recursion/LMA/mlms.mod.so: Permission denied
make: stat: lib/home/rudra/Recursion/LMA/mlms.mod.a: Permission denied
make: *** No rule to make target `-l/home/rudra/Recursion/LMA/mlms.mod', needed by `main.o'. Stop.

where permission denied, i guess means, no such file exist. what to do?
0 Kudos
Ron_Green
Moderator
1,669 Views
Quoting - roddur
[cpp]main.o : main.f90 ~/Recursion/LMA/liblm.a -l/home/rudra/Recursion/LMA/mlms.mod
[/cpp]
while compiling using -l, i get the error:

make: stat: lib/home/rudra/Recursion/LMA/mlms.mod.so: Permission denied
make: stat: lib/home/rudra/Recursion/LMA/mlms.mod.a: Permission denied
make: *** No rule to make target `-l/home/rudra/Recursion/LMA/mlms.mod', needed by `main.o'. Stop.

where permission denied, i guess means, no such file exist. what to do?

The font in the browser may be confusing you. Steve said to use -I, the first letter in the word Include. It looks like you have -l as in the first letter of library - this is wrong. It must be -I as in Include.
0 Kudos
TimP
Honored Contributor III
1,669 Views

The font in the browser may be confusing you. Steve said to use -I, the first letter in the word Include. It looks like you have -l as in the first letter of library - this is wrong. It must be -I as in Include.
It's probably OK to make a .a library of .mod files, but I would expect that to require adding lines to your Makefile to extract the .mod file when it is to be used. I don't see how a .so file of .mod files would be usable. The usual way would be to have the .mod files unpacked in the directory referred to by the -I include path. Further to what Ron said, in this context, -L is understood by the linker as a library path designation; lower case -i or -l wouldn't have any meaning other than as a subdirectory.
I can't read your next post, but I can state that -I~/ or -L~/ will not work in place of -L/home/yourlogin/ or -I/home/yourlogin/ This is general linux practice, not specific to Intel compilers.
0 Kudos
roddur
Beginner
1,669 Views
-I is not working either. Let me explain in more details what i have done.
first i have created a library in directory ~/Recursion/LMA using makefile:
[cpp].f.o:
	$(FC) -c $(PREFLAGS) $(FFLAGS) $<
	mv $(*F).o $(*D)
#
.c.o:
	$(CC) $(CCFLAGS) -c $<
	mv $(*F).o $(*D)


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 r liblm.a lm-lib.o lm-lib-end.o $(lmobj)[/cpp]

Now, i want to use this in my main code,in die ~/Recursion/ASR/, compiling as:
[cpp]irun: $(FOBJ)
	$(FC) -o $@ $(FFLAGS) $(FPAR) $(FOBJ) /home/rudra/Recursion/LMTO-A/liblm.a

hop.o : hop.f90 param.o kind.o 
	$(FC) -c $(FFLAGS) $(FPAR) hop.f90 $(LIBFLAGS) 
kind.o : kind.f90 
	$(FC) -c $(FFLAGS) $(FPAR) kind.f90 
ldos.o : ldos.f90 param.o 
	$(FC) -c $(FFLAGS) $(FPAR) ldos.f90 
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 -I~/Recursion/LMTO-A -llm
	$(FC) -c $(FFLAGS) $(FPAR) main.f90  -I~/Recursion/LMTO-A -llm

[/cpp]
while i am making this, it is yeilding error:
[cpp]$ make
make: *** No rule to make target `-I~/Recursion/LMTO-A', needed by `main.o'. Stop.


[/cpp]
but if i compile things simply as
$(FC) -c $(FFLAGS) $(FPAR) main.f90 ../LMTO-A/liblm.a
then it is compiling(not using the .mod file though), and with a constraint that my liblm.a and main.f90 should be compiled with same compiler, which i dont think a library should do. plz help.
0 Kudos
Kevin_D_Intel
Employee
1,669 Views

Library paths are specified with -L (capital L) option, not -I(capital I) but you may need both to access your .mod files and library. To compile and link you probably need :

$(FC) -c $(FFLAGS) $(FPAR) main.f90 -I/home/ruda/Recursion/LMTO-A -L/home/ruda/Recursion/LMTO-A -llm

The make failure involves line 10 and the -I and -l compiler options you added. Those are needed on line 11 as you have placed them but those are not appropriate for line 10.
0 Kudos
roddur
Beginner
1,669 Views
So now my makefile looks as:
[cpp]irun: $(FOBJ)
	$(FC) -o $@ $(FFLAGS) $(FPAR) $(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]


which gives error:
ld: cannot find -lm
make: *** [irun] Error 1
i also tried without linking lm in linking; with no luck. how to link?
0 Kudos
Kevin_D_Intel
Employee
1,669 Views

Maybe there's cut-n-paste problem here, but I cannot really tell why that's occurring from the snippets and now your main.o rule looks like one continuous line.

I also was misleading in my earlier post having overlooked the -c option for the main.o rule. The main.o rule is compiling only, therefore, -L and -l are not appropriate options. It could be that rule threw the last error you received.

As Tim mentioned earlier, if you trying to convince the compiler to use a static archive (.a) comprised of .mod files (not .o files) during the compilation phase of main.f (which seems to be what you were after by mixing -I and -l originally), then that won't work. The compiler only seeks to open files ending with .mod from a directory notstatic archive (.a), which is why Tim suggested your makefile needs to extract the .mod files from the static archive for the compiler to see/use those. The linker processes static archives at link time only.

0 Kudos
roddur
Beginner
1,669 Views
Well, I in in trouble, as i mention earlier. My library is compiled with gfortran. My main code is getting compiled with gfortran; but not ifort.
is it ok? i think i am missing something as it should not be the case.
0 Kudos
Kevin_D_Intel
Employee
1,669 Views


I may be abit confused about your end goal.

If you're trying to create a static archive of gfrotran object files and have ifort (when compiling your main program) use any associated gfortran produced module files, then that will not work. ifort has no understanding of gfortran module files.

Also, you cannot expect to resolve any external dependencies from your gfortran objects in your static archive from the ifort run-time libraries at link time when compiling/linking your main program.

If the desire is to use a non-Intel compiler for your static archive and the Intel compiler for any program that uses that static archive, then you cannot leverage the USE and you must ensure your static archive does not accidentally use any ifort run-time libraries when linked.

0 Kudos
Reply