Dear PGI forum members
I would like to ask for your help in resolving a problem, I have encountered when using precompiled libraries.
I have a library produced in the standard manner:
ar rcvf libTEST.a heat_cond.o sub1.o module1.o sub2.o module2.o etc.
The object files from above are in fact modules and functions of a big FORTRAN subroutine (compute heat conduction).
Then I call the heat_cond subroutine inside some other main program. I compile the code via the standard:
pgf90 -o EXAMP main.f90 -L /path/to/lib -lTEST
My problem is that I would like to use one of the modules contained in libTEST.a in my main program. If I would like to do so I have to compile in the following manner:
pgf90 -o EXAMP module1.f90 main.f90 -L /path/to/lib -lTEST
Is it possible to link the module, which is inside libTEST.a to the main without doing the above procedure, or I am doing something wrong with the library?
I link this
You need to add the path(s) to the module files on the link line. This can be done using either the “-I” option or “-module” option. For example:
pgf90 -o EXAMP main.f90 -I/path/to/mod_files -L /path/to/lib -lTEST
pgf90 -o EXAMP main.f90 -module /path/to/mod_files -L /path/to/lib -lTEST
If you have multiple directories that contain module files, add additional “-I” or “-module” options on the link line.
Thank you for your replay. However there is something I do not understand. The module files are inside the library. Why the compiler can’t see them. If I use,
ar t libTEST.a
I can see them listed.
I think I understand the source of the compiling/linking problems. You may (incorrectly) have assumed that when you compile Fortran source code and archive the files into a “module library” everything is contained in the library (*.a, *.so) file.
Not so. When you compile a Fortran source containing Fortran modules (i.e., with MODULE…END MODULE statements), two files are produced: a “Fortran module” file, .mod, and the object file, .o. It is rather common for “load module” and “Fortran module module file” to be confused. The former term comes from IBM, going back to the 1960s. The latter did not exist until a couple of decades later, when Fortran 90 was being designed.
When you compile a number of Fortran module sources and build a “load” or “link” library, only the *.o files are put into the library. The *.mod files are still outside the library, and the compiler needs to know where they are when compiling Fortran sources that contains USE statements for those modules.
Thank you for your answer, it is all clear now.
Have a nice day