PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Link modules contained inside a fortran library

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
wronski11



Joined: 15 Jun 2011
Posts: 8

PostPosted: Fri Jun 22, 2012 6:57 am    Post subject: Link modules contained inside a fortran library Reply with quote

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:
Code:
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:
Code:
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:
Code:
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
Back to top
View user's profile
toepfer



Joined: 04 Dec 2007
Posts: 47

PostPosted: Fri Jun 22, 2012 11:04 am    Post subject: Reply with quote

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:

Code:
pgf90 -o EXAMP  main.f90 -I/path/to/mod_files -L /path/to/lib  -lTEST

or

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.
Back to top
View user's profile
wronski11



Joined: 15 Jun 2011
Posts: 8

PostPosted: Sat Jun 23, 2012 7:52 am    Post subject: Reply with quote

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,
Code:
ar t libTEST.a
I can see them listed.
Back to top
View user's profile
mecej4



Joined: 19 Jun 2011
Posts: 54

PostPosted: Sat Jun 23, 2012 6:32 pm    Post subject: Confusion about "modules" and "module files&a Reply with quote

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, <modulename>.mod, and the object file, <filename>.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.
Back to top
View user's profile
wronski11



Joined: 15 Jun 2011
Posts: 8

PostPosted: Mon Jun 25, 2012 12:01 am    Post subject: Reply with quote

Thank you for your answer, it is all clear now.
Have a nice day
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group